Home » Infrastructure » Unix » delete last character from every line in a text file (Unix)  () 1 Vote
delete last character from every line in a text file [message #352750] Thu, 09 October 2008 05:41 Go to next message
Orac_NewBhie
Messages: 2
Registered: February 2008
Location: Manila, Philippines
Junior Member
Hi All,

I'm in dire need to find a unix script (linux or solaris) that will delete the last character from every line in a text file.

Example here: text1.dat contains the following line

0000,house,car,room,school,education,economy,
1111,house,car,room,school,education,economy@
2222,house,car,room,school,education,economy#
3333,house,car,room,school,education,economy%
4444,house,car,room,school,education,economy&


Please help me create a script that will automatically delete the last character from every line in a text file (,@#%&)

Please help me.

Thank you!
Re: delete last character from every line in a text file [message #352754 is a reply to message #352750] Thu, 09 October 2008 05:58 Go to previous messageGo to next message
Michel Cadot
Messages: 64109
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Note that this is an Oracle forum.

Here's one way:
sed 's/.$//' myfile >myoutput

Regards
Michel
icon7.gif  Re: delete last character from every line in a text file [message #354817 is a reply to message #352754] Tue, 21 October 2008 06:58 Go to previous messageGo to next message
Orac_NewBhie
Messages: 2
Registered: February 2008
Location: Manila, Philippines
Junior Member
Thank you Michel! Surprised

I really appreciate it.

This is inline with flat file that I'm trying to import into an Oracle database, which need some editing before import.

Do you also know a script that will replace the last character in a row with a different character or insert a word inside every row?

I hope you could also help me with this one. Surprised

Again, thank you so much!
Re: delete last character from every line in a text file [message #354819 is a reply to message #354817] Tue, 21 October 2008 07:17 Go to previous message
Michel Cadot
Messages: 64109
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
You should search for "sed" on Google, you can do many things with it, it is a String EDitor.
Also you could post your question in Unix forum (this is an Oracle forum), you will likely get more appropriate answer.

Regards
Michel
Previous Topic: Suppressing output
Next Topic: shell script
Goto Forum:
  


Current Time: Mon Dec 05 10:42:43 CST 2016

Total time taken to generate the page: 0.24558 seconds