grep - remove lines which only contain whitespace.
1 Attachment(s)
I'm having some trouble getting grep to remove lines from a file which only contain white space characters.
The attached file contains lines which are commented out by having a # at the start, lines which are empty and lines which contain either just some spaces or tab characters. I want to use grep to remove all the aforementioned types of line and end up with lines 2 3 6 13. I thought that this would work: grep -ve ^# lines.txt | grep -ve ^$ | grep -ve '^\s*$' But it doesn't. The first and second greps do what I expect. The first one removes the commented out lines, the second removes the empty lines. The last grep, which I think should remove lines containing only whitespace characters doesn't remove anything and I can't figure out what the correct regexp should be. Anyone know? |
Hi,
egrep -v "^[ ]*$|^#" lines.txt There is a space and a tab between the square brackets. A tab can be 'cerated' by: ctrl-v then tab Hope this helps. |
Quote:
Code:
egrep -v "^[ \t]*$|^#" lines.txt |
Hi again,
I don't get the objection: 1) If you use this as a oneliner you type as you go and the oneliner is forgotten after you use it (getting it back from your history is a possibility). 2) If this is used in a script: A comment above the command should solve the forgetting part. Anyway, here's another solution (but more typing... ;) ): egrep -v "^[[:space:]]*$|^#" lines.txt |
That's great, thanks a lot.
|
All times are GMT -5. The time now is 08:27 AM. |