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

convert a file using awk 1

Status
Not open for further replies.

andrero

Technical User
Feb 11, 2002
13
0
0
NL
Hello scripters,

I'd like to convert a file like
<$ MG_nr>
<!200>company-type
<!210>company-name
<!220>address
<!230>nr
<!240>zipcode
<!250>place
<!260>phone
<!270>fax
</$>
<$ MG_nr>
<!200>company-type
<!210>company-name
<!220>address
<!230>nr
<!240>zipcode
<!250>place
<!260>phone
</$>

...

into:
company-type!company-name!address!nr!zipcode!place!phone!fax
company-type!company-name!address!nr!zipcode!place!phone!fax
...

I guess I should use awk but I'm not very familiar with it, any help appreciated.

Regards, AndreRo
 
Expand on:

awk -F\> '{ if ( $1 == &quot;<!200&quot; ) { ct=$2 }
else if ( $1 == &quot;<!210&quot; ) { cn=$2 }
else if ( $1 == &quot;</$&quot; ) { print ct &quot;!&quot; cn };
}' inputfile > outputfile

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top