![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
LinkBacks (?)
LinkBack to this Thread: http://www.unix.com/shell-programming-scripting/28780-trying-remove-m-characters-file.html
|
||||
| Posted By | For | Type | Date | |
| jatorrero's Bookmarks on Delicious | This thread | Refback | 12-26-2008 07:59 AM | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to remove null characters from file? | siegfried | UNIX for Dummies Questions & Answers | 1 | 04-02-2008 01:02 AM |
| remove space characters | melanie_pfefer | Shell Programming and Scripting | 1 | 03-11-2008 01:45 PM |
| How to remove Characters before '~' | Amey Joshi | UNIX for Dummies Questions & Answers | 4 | 01-07-2008 06:43 AM |
| remove multiple characters once | norsk hedensk | Shell Programming and Scripting | 2 | 08-04-2003 03:13 PM |
| Remove control characters | aravind_mg | UNIX for Dummies Questions & Answers | 5 | 10-02-2002 02:07 PM |
![]() |
|
|
LinkBack (1) | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
||||
|
Trying to remove '^M' characters from a file.
Hi guys,
Hope you are all well. This is a line of data from a csv file. I have used vi and set the 'set list' option to display the trailing $ character. "01","Grocery","01006","eat Fish & Spreads"$ I have tried the following commands, but neither of them appear to be working? 1) tr -d "^M" < originalfile.csv > newfile.csv 2) tr -d "\015" < originalfile.csv > newfile.csv ....but when I vi & set list the new file, I am still seeing the trailing $ character in the file. Can anyone please tell me where I am going wrong? Thanks in advance, Kev |
|
||||
|
Hope this helps.
I had a big issue with this while trying to get a flat file into Oracle. I tried using vi and sed, and ultimately came upon a solution using strings and tr. Here is my shell script: #make a backup cp $1 $1.orig #Strip out nulls. tr -d ‘\0′ < $1.orig > $1.temp #Strip out other unprintable characters strings $1.temp > $1 #Remove temp file. rm $1.temp #Fix permissions. (You may not need this for your application) chmod 744 $1 |
|
||||
|
Have you misunderstood vi's "set list". What it does is print a "$" sign at the end of each line (and show tabs as ^I). The $ sign isn't in the file itself it is just displayed to make it easier for you to spot things like trailing spaces at the end of lines.
cheers |
|
||||
|
The "^M" things are from dos/windows files. dos carriage returns are "\n\r", unix "\n" The extra character shows up as "^M". Use dos2ux (or dos2unix depending on your flavor of unix) to convert windows text files. Code:
dos2ux oldfile > newfile |
|
||||
|
Thanks for the swift response guys - much appreciated. Thestevew was right - I was misunderstanding the vi 'set list' option, so thanks for putting me straight. I eventually came up with a couple of possibilites - I could use the unix2dos command within a batch file to properly format my csv file. I also found another thread on this forum with the following perl command... Code:
perl -i -pe 's/$/\r/' myfile.csv I'll probably use the perl command to avoid implementing a batch file. Plus, I don't have to output the results to a new file. Out of interest, does anyone know of a sed command that would do the same as the above perl command? Thanks again, Kev |
![]() |
| Bookmarks |
| Tags |
| shell script, shell scripting, unix scripting, unix scripting basics |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|