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!

help converting csv file format w/ AWK or SED... 3

Status
Not open for further replies.

admoore

IS-IT--Management
May 17, 2002
224
US
I have comma delimited files that have data similar to this:
Code:
50211,JHMCG5661YC025824,60,LOF,29.95
,,60,BAL,14.95
,,60,ALN,79.95
50212,JHMCG4732XC047827,60,LOF,29.95
etc...
Specifically, my problem is that the data must be imported into an
ACCESS database, and the report format does not repeat certain field
info until they change...

What I need to see in this case would be:
Code:
50211,JHMCG5661YC025824,60,LOF,29.95
50211,JHMCG5661YC025824,60,BAL,14.95
50211,JHMCG5661YC025824,60,ALN,79.95
50212,JHMCG4732XC047827,60,LOF,29.95
etc...
Although I dont believe that this would be too difficult in SED or AWK
I am not sure how exactly to approach it...

The actual files contain many more fields than this example.

TIA,

-Allen Moore
 
sed '
/^[0-9].*/{
h
s/\([^,]*,[^,]*\).*/\1/
x
b
}
s/,//
G
s/\(.*\)\n\(.*\)/\2\1/
' input

or

awk -F"," 'BEGIN{
FS=","
}
$1 != ""{
A=$1
B=$2
print
next
}
{
$1=A
$2=B
print
}' input Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
I put in the field separator twice for the awk example. Keep one of your choice and drop the other. Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top