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!

Awk Question 1

Status
Not open for further replies.

HIB049

Technical User
Jan 31, 2003
19
GB
Hi Guys,

What is the quickest way to do the following?

Name Address Tel No email website Fax No

to

Name#Address#Tel No#email#website#Fax No


Your comments would be kindly appreciated.

Thanks

Ed
 
Fancy that... an "Awk Question" in the AWK forum. :) Please consider giving your threads more descriptive titles...

Are the fields just separated by spaces... i.e. no tabs? If so, I'd suggest replacing the spaces with hashes, and then replace "#No" with " No".

Code:
awk '{[b]gsub[/b]([red]"[/red][purple] [/purple][red]"[/red],[red]"[/red][purple]#[/purple][red]"[/red],[blue]$0[/blue]); [b]gsub[/b]([red]"[/red][purple]#No[/purple][red]"[/red],[red]"[/red][purple] No[/purple][red]"[/red],[blue]$0[/blue]); [b]print[/b]}' inputfile > outputfile

However I'd recommend using sed instead for that job:

Code:
sed 's/ /#/g;s/#No/ No/g' inputfile > outputfile

Annihilannic.
 
or even [tt]tr[/tt]

Code:
tr ' ' '#' <inputfile >outputfile

HTH,

p5wizard
 
Thanks guys for getting back on this one, sorry it was late in the night when I was typing, so could think of a descritive subject. But thats absolutly wonderful. Thanks once again for the response.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top