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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remove empty lines

Status
Not open for further replies.

BIS

Technical User
Jun 1, 2001
1,893
NL
Hallo All,

I have a small awk script rewriting a file. I would love to remove all empty lines. If I "cat -A filename" it looks like this:

some text
some more text
$
$
$
yet more text
$


How do I remove the empty lines?

I tried:
/^$/ ; $0 = ""
print; next }

...in my script but that didn't work

 
awk 'NF' filename

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hallo PHV,

Thanks for your input. I am actually calling the awk script with an 'awk -f' statment, how would I implement above solution there?

Here is a snippet to maybe better explain:


# Set field-separator.
BEGIN { FS = " *: *" }
# Remove trailing spaces.
{ sub(/[ \t]+$/, "") }
#
/^Address/ { pr(); $0 = "<address>"$2"</address>"
print; next}
#
#
/^City/ { pr(); $0 = "<city>"$2"</city>"
print; next}
#
#
/^Postal Code/ { pr(); $0 = "<zip>"$2"</zip>"
print; next}
 
...
BEGIN { FS = " *: *" }
!NF{next}
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top