Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

please advice

I have linux and solaris machines, and I need command that work on both OS

I use the following perl line in order to remove all lines that start with "#" why perl command not work ,

remark - need to support also lines that start with space or TAB and then "#"

 perl -i -pe 'next if /^ *#/' file


   more file

   # aa a
       #  bbb 

share|improve this question
up vote 3 down vote accepted

this will work on linux maybe also on solaris

sed -e '/^\s*#/d' file

EDIT: If \s is not supported maybe this will work...

sed -e '/^[ \t]*#/d' file

To do that in file just add -i to the command

If you don't want consecutive multiple blank lines in the result, just pipe it through uniq

share|improve this answer
not work if before "#" I have space or TAB – yael Nov 18 '12 at 14:13
you're sure? it does for me... On which OS does it not work, only solaris? – andrekeller Nov 18 '12 at 14:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.