tags:

views:

40

answers:

2

How to remove line that begins with three #

For example need to delete all the following lines: from file

1 ### bla bla bal

2 ###blablabla

3 ### blabla

. . .

THX Yael

+2  A: 
cat file | sed '/^###/d'
Steve Weet
+1, except that there is no need for cat ;)
unbeli
Well if you try it without it will sit there for a long time ;)
Steve Weet
you pass the file as input to sed. `sed '/^###/d' file`
ghostdog74
We could get into a long discussion of how *nix scripts should always be pipes from STDIN/STDOUT but yes, sed will take one or more file arguments on the command line.
Steve Weet
@Steve sed '/^###/d' < file
unbeli
from my point its better to use the awk but how to change sed in order to do what awk do?
yael
for example cat file | sed '/^###/d' not effect if some space before the "###"yael
yael
@unbeli, and there's no need for input redirection
ghostdog74
@ghostdog74 and there is no need to repeat yourself ;)
unbeli
@unbeli, what are you referring to? i am talking about the "<" in `sed ... < file` that you propose. This is technically not the same as `cat file| sed ...`. so which part am i repeating myself?
ghostdog74
@ghostdog74 how is sed < file different from cat file | sed, except sparing some time?
unbeli
@yael. The reason this does not remove lines beginning with spaces or tabs followed by ### is that this was not asked for. You can do that with `sed '/^[\t ]*###/d'` the same as the awk command.
Steve Weet
@everyone. Can we please accept that sed will read input from STDIN (Whether piped or redirected) or from one or more filenames provided as paramaters on the command line. This comment thread is getting silly
Steve Weet
+1  A: 

you can use awk as well

awk '!/^[ \t]*###/' file
ghostdog74