HI,
I have a file with lot of blank lines, how can I remove those using awk??
Thanks,
Shruthi
HI,
I have a file with lot of blank lines, how can I remove those using awk??
Thanks,
Shruthi
hey you can use
awk '/./' infile for removing blank lines
can you please explain me how this command works...I mean I don't have any '.' in my file to search for ??
awk '!/^$/ {print $0}' test.txt
In this context the '.' is not a literal dot/period, but a regex special character/metacharacter that matches (almost) any single character ( reference: Regex Tutorial - The Dot Matches (Almost) Any Character )
So, here it matches all lines that contain any character (ie: that aren't blank). Note if lines contain spaces these are counted as characters so will still be printed, eg:
$ printf 'line1\n \nline3\nline4 with spaces\n\nline6\n'|awk '/./'
line1
line3
line4 with spaces
line6
(line 2 consists of a space, so is still printed. line 5 is a blank line, so it is omitted)