Berkeley CSUA MOTD:Entry 27558
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/25 [General] UID:1000 Activity:popular
5/25    

2003/2/27-28 [Computer/SW/Languages/Perl] UID:27558 Activity:high
2/27    How do I remove blank lines and comment lines (starting with `#`)
        from a file?     - unix newbie
        \_ sed/awk, perl, java, c, c++, etc
                \_ hi asshole!
                   \_ BWAHAHAHA!  You just made my day!
                \_ how do I use the "etc" command?  I have this thing called
                   "etc" on my computer but I can't run it.  How to run etc?
        \_ grep -ve ^# -e "^[ ]*$" file > newfile
           (this will also remove lines with just whitespaces)
        \_ perl -ni -e 'print unless /^(#.*|\s*)$/' filename
           ...I think.  And there's no real need to delete or overwrite
           my entry unnecessarily just because you don't like perl.
           Note that this will edit the file in place, as the question
           implies.
           -geordan
           \_ What's the perl manpage to see what various commandline args
              do? I use -p, but don't know what -n does.
              \_ perldoc perlrun
                 -n is the same as -p, except it doesn't print $_ at the
                 end of the loop. -geordan
        \_ Thanks for all the help!  - op