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!

SED last delimiter from unload file

Status
Not open for further replies.

gkrenton

MIS
Jul 2, 2003
151
US
I've created a script that unloads a file as a comma-delimited txt file (orderfile.txt). The gotcha is that after the last record there is a comma that I need to remove.
IE The comma at the end of the line as shown below.
9,002,7,095,92.0,2318.08,1025.45,
11,899,6,075,0.0,0.0,0.0,
6,002,3,010,91.0,3154.09,1462.5,

I know the SED command is probably the solution but I'm not getting how to format the sed script to do what I'm trying to accomplish. I've read through a gazzillion how-to pages in multiple sites but none of them really explain/show to a total neophyte like me how to put this concept in place.

I think it's supposed to look something like this but this isn't working.

sed -e '$s,\\,,' > newonfile.txt

Thanks in advance

Gina
 

Did you try:

sed -e '$s/$,//' > newonfile.txt

[3eyes]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Hadn't tried it but still have comma's at the end of the line.
I've typed:

sed -e '$s/$,//' dsonorder.txt > dsonodernc.txt
& results are the same
11,002,6,075,30.0,2399.7,1110.0,
17,098,1,010,0.0,0.0,0.0,

Got another idea?

thanks

gina
 
I think I stumbled upon it -
this seems to work
sed -'s/,$//' onorderold.txt > onordernew.txt

guess e was a red herring.

- gina
 
you only need the -e if you are going to do more than one sed command.

Ie

sed -e 's/pattern/pattern/g' -e 's/some other pattern/some other pattern/g'
 
Thanks - guess I didn't pick that up in all the documents & online resourcs I've perused over the last day & half trying to figure it out. Good to know for future use.

gina
 
The very first thing to do before any research:
man sed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top