Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Skip blank lines 1

Status
Not open for further replies.

7280

MIS
Apr 29, 2003
331
IT
Hi,
i have a file with some blank lines.
I want to create a new file without the blank lines.
How can i do?
I'm using this command
awk -f script.awk file1.txt > file2.txt

where script.awk is:
BEGIN {
if ( $0 =! "" ) print $0
}

Syntax Error The source line 2.
The error context is
BEGIN >>>
<<<
awk: 0602-500 Quitting The source line is 2

Please help.
Thanks
 
A blank line has a NF = 0, because it's not &quot;tokenizable&quot;, so try something like:
cat your_file|awk '( NF > 0 ) { print $0 }'
 
The BEGIN pattern is carried out before the first file is read, so you can't use $0 in its code.

Jean Pierre.
 
The awk way:
Code:
awk 'NF' /path/to/file
The sed way:
Code:
sed '/^[  ]*$/d' /path/to/file
(Note: inside square brackets are a space and a tab)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top