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!

Stripping a record from file. 1

Status
Not open for further replies.

iangodsell

Programmer
Jan 30, 2002
1
AU
Hi,

I am trying to put together a one liner unix script to get the following output.

4,2,774,421
2,7,134

where the original records in a file filename.csv are

4,2,774,421,|3||||Destination|Error Demo|1|12 APR 2002
2,7,134,|1|Lookup Failure|Address_ID|7|Destination|Error Demo|1|12 APR 2002

The best I can get to is
4,2,774,421,
2,7,134,

using

cut -f 1 -d '|' filename.csv

As you can see though, the commas at the end are still there.

Thanks to all in advance.

Regards,

IanG.
 
nawk -F "|" '{printf("%s\n", substr($1, 1, length($1)-1))}'
 
Hi:

cut -f 1 -d '|' filename.csv|tr -d ,

Regards,

Ed
Schaefer
 
Hi:

Sorry, I got rid of all the commas. I should read closer.

Ed
 
Good job bigoldbulldog. Half the battle with UNIX is recognizing the regular-expression. Too often we can't see the comma for the trees. Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top