I tried grep -v '^$' in Linux and that didn't work. This file came from a Windows file system.
+2
A:
Try the following:
grep -e "^$" -v foo.txt
The -e
option allows regex patterns for matching.
UPDATE: This works for me for a file with blank lines or white spaces on windows:
egrep -v "^[[:space:]]?$" foo.txt
ars
2010-08-08 00:17:13
It's still showing blank lines.
awakeFromNib
2010-08-08 00:24:33
See update to the question.
ars
2010-08-08 00:52:39
Yeah that works. It also works with grep.
awakeFromNib
2010-08-08 01:15:20
A:
I prefer using egrep
, though in my test with a genuine file with blank line your approach worked fine (though without quotation marks in my test). This worked too:
egrep -v "^(\r?\n)?$" filename.txt
chryss
2010-08-08 00:20:42
Tried that. Blank lines are still showing. Could this be because the file was made in Windows?
awakeFromNib
2010-08-08 00:25:36
+1
A:
Tried hard but this seems to work (assuming \r
is biting you here)
printf "\r" | egrep -xv "[[:space:]]*"
mvds
2010-08-08 00:50:25
A:
$ dos2unix file
$ grep -v "^$" file
Or just simply awk
awk 'NF' file
If you don't have dos2unix, then you can use tools like tr
tr -d '\r' < "$file" > t ; mv t "$file"
ghostdog74
2010-08-08 01:10:40
Can't find the program dos2unix. Is that for Windows? the ask command doesn't work either.
awakeFromNib
2010-08-08 01:36:43