|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Removing ^M through shell script
Hi all, I am trying to write a ksh script to remove controlM characters from the input csv file. I tried following command Code:
sed 's/^M//g' $DIR/$FILENAME > $DIR/$Temp_FILENAME while writing the code i had to press CTRL key then V then M (to type ^M) Cant I write ^M without pressing ctrl+V ctrl+M?? Problem is when I migrate the code to some other server I have to bring the code to Windows and then to the next Unix server and the ^M char gets lost in windows. Is there a way that sed command can read ^M without pressing ctrl+ V M manually??. e.g [CTRL]V M so that i dont have to manually type in ^M in the script in production Please help. Thanks Last edited by DukeNuke2; 02-08-2010 at 06:06 PM.. Reason: code tags please! |
| Sponsored Links | ||
|
|
|
#2
|
||||
|
||||
|
Code:
tr -d \\015 < file |
|
#3
|
|||
|
|||
|
example using sed
Here is an example that should process all of your .csv files. Code:
for CSV_FILE in *.csv;
do if [ -f $CSV_FILE ];
then sed -e 's/\x0d//g' $CSF_FILE > /tmp/foo.$$;
mv /tmp/foo.$$ $CSF_FILE;
fi;
done |
|
#4
|
|||
|
|||
|
Resolved
thanks everyone following also works fine in the script Code:
sed 's/'"$(printf '\015')"'$//g' $DIR/$FILENAME > $DIR/$Temp_FILENAME Thanks again Last edited by scottn; 02-09-2010 at 02:59 AM.. Reason: Again, code tags please... |
|
#5
|
|||
|
|||
|
To replace the ^M 's on the screen in vi type
:%s/\r// What that says is: for lines 1 to end, replace \r with nothing . This will replace only one instance of ^M per line. If you have two on a line for some reason simply run the command a second time. The th^Me thus providing t^Mhe ability to change characters, ^mwords, and lines I tried doing it in command mode with this text in my vi editor... It doesnt delete ^M, but it threw me an error E486: pattern not found: r// Please explain in detail. |
|
#6
|
||||
|
||||
|
Try this Code:
:1,$ s/[ctrl-key+v and ctrl-key+M]//g but actual command would be :1,$ s/^V^M//g |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| removing new line from the shell variable value | thegeek | UNIX for Dummies Questions & Answers | 5 | 10-07-2009 11:06 AM |
| best way for removing comment from shell scripts -- bash | thegeek | Shell Programming and Scripting | 2 | 09-15-2009 09:36 AM |
| Removing the entire file contents using unix shell script. | praka | Shell Programming and Scripting | 5 | 02-10-2009 02:34 AM |
| help removing characters for output file in shell script | wingchun22 | Shell Programming and Scripting | 1 | 08-02-2008 12:55 AM |
| Removing line breaks from a shell variable | lyonsd | Shell Programming and Scripting | 5 | 09-12-2006 01:42 PM |