Berkeley CSUA MOTD:Entry 11036
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/07/08 [General] UID:1000 Activity:popular
7/8     

2003/11/12 [Computer/SW/Languages/Perl] UID:11036 Activity:nil
11/11   Argh.  Why isn't this working?
        perl -p -i.bak -e 's#\n\n#\n#gsm' foo.cc
        I've got to change
        /* comment */

        int
        TO
        /* comment */
        int
        \_ man perlrun, and look at the explanation of -p. --scotsman
        \_ s/^\n// worked for me. and no emacs needed.
        \- you can use an emacs kbdmacro, then use the macro2elisp
           "complier" and then tweak the function to do this.
           there might be a simpler way to do this with
           query-replace* ... depends on the exact details. --psb
        \_ I wound up doing s/\n/FOOBAR/g; s/FOOBARFOOBARint/FOOBARint/g;
           s/FOOBAR/\n/g; .  That's it.  Fuck this, I'm leaving.  And
           thanks for the suggestions.
           \_ The reason it didn't work is b/c -p only gets one line at a time,
              so the entire string you get to match is, for instance,
              "/* comment */\n", not the 3 lines you were looking for.
              Getting rid of the \n's first let you have it all on one line.
              \_ perl -p -i.bak -e 's#^\n##' foo.cc