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!

Parsing a file 1

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
US
I'm having trouble parsing what should be something simple.

I have an input file with lines like this:

domain1.com

domain2.net

domain4.com

...

etc.

So usually there are 2 lines per record, but sometimes there will be just 1.

The desired output is:

domain1.com domain2.net domain4.com

I managed to get some output using this:

$1 !~ /http/{domain = $1}
/http/{destination = $1; printf ("%-50s %-50s\n", domain, destination)}

But I'm not sure that it's the most accurate/efficient method. I can't recall the best combination of ORS/OFS/IFS/IRS to use to achieve what I'm looking for.

Any help would be appreciated.

Thanks,

John
 
A starting point:
Code:
NF{d=$1;getline;print d,$1}

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV! Have a star!

I was drawing a blank as to how to deal with it. I had thought of using getline, but not the NF.

What does the NF outside of the brackets actually mean?

What I ended up using is below.

awk 'NF{domain=$1;getline;printf ("%-50s %-50s\n", domain,$1)}'

Thanks,

John
 
What does the NF outside of the brackets actually mean
It's the same as NF!=0

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

Part and Inventory Search

Sponsor

Back
Top