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!

awk help

Status
Not open for further replies.

AlStl

MIS
Oct 2, 2006
83
US
I am new to awk or nawk and inherited a script (add1.awk) , which is as follows:

#!/bin/nawk -f
{
gsub(/\015/, "")
gsub(/^ *$/, "")
}

I am issuing this command at the prompt:
add1.awk file.txt

file.txt is as follows (as you can clearly see it has bunch of blank lines in it):

Jane Doe
123 Main Street
Anywhere, SE 12345-7890

John Smith
456 amit-lined Avenue
Smallville, MW 11111-0000

Can someone explain to me what these two gsub are for i.e.

gsub(/\015/, "")
gsub(/^ *$/, "")

It seems that they are not doing anything even when I redirect it to output.txt file:

add1.awk file.txt > output.txt

output.txt is same as file.txt so these two function are not doing anything to input file. I was hoping atleast one of the function is to remove blank lines.

Thanks,

Al
 
remove blank lines
awk '!/^ *$/' file.txt

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

Part and Inventory Search

Sponsor

Back
Top