Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Example of the data file is pipe delimited and looks like this.^M is only scattered around certain lines in the file.
A|Data1|Data2|Data3|Data4|Data5|
A|Data1|Data2|Data3split^M
data3split|Data4|Data5|
A|Data1|Data2|Data3|Data4|Data5|
A|Data1|Data2split^M
data2split|Data3|Data4|Data5|
A|Data1|Data2|Data3|Data4|Data5|Anyone knows a simple way (sed or awk) to remove the ^M and linefeed that splits the data line?

oh forgotten to add data can also split to more than 2 rows
e.g.
A|Data1|Data2|Data3|Data4|Data5|
A|Data1split^M
data1split|Data2|Data3split^M
data3split|Data4|Data5split^M
data5split|
A|Data1|Data2|Data3|Data4|Data5|Side note:
Web applications and all these 'new' XML seems to take us a huge step backways in terms of data validation at the UI to validate users' inputs don't they?

Hi..to remove ^M, give the command :
sed -e 's/^M//g' filename
you will have to write the control-M as follows : first press control-V,then control-M,this will show the correct control-M on the command line.
For removing the linefeeds,try this :
sed -e 's/.$//g' filename
this will remove the last character from the line,which happens to be the line feed.

I simply use dos2unix.
Anupam, i didn't get your linefeed removal line.
Can you explain me a bit. What does here .$ signify.Thanks
Vibhor Kumar Agarwal

There's other ways to delete control-m besides embedding ^M:
1) Using tr:
tr -d '\015' filename
2) Using sed:
sed 's/'"$(printf '\015')"'$//g' filename

the .$ will remove the last character from each line.In your case,the last character will be the linefeed which will be removed by the sed command.In the case of converting from DOS to UNIX,the last character of the line will be the carriage return,which will be removed.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |