Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Remove ^M and line feeds

Original Message
Name: stslim
Date: May 23, 2005 at 18:49:26 Pacific
Subject: Remove ^M and line feeds
OS: HP Unix
CPU/Ram: HP 4 gb
Comment:
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?


Report Offensive Message For Removal


Response Number 1
Name: stslim
Date: May 23, 2005 at 19:08:33 Pacific
Subject: Remove ^M and line feeds
Reply: (edit)
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?


Report Offensive Follow Up For Removal

Response Number 2
Name: anupam
Date: May 23, 2005 at 21:11:55 Pacific
Subject: Remove ^M and line feeds
Reply: (edit)
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.


Report Offensive Follow Up For Removal

Response Number 3
Name: vibhor_agarwalin
Date: May 23, 2005 at 21:28:58 Pacific
Subject: Remove ^M and line feeds
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 4
Name: nails
Date: May 24, 2005 at 09:22:33 Pacific
Subject: Remove ^M and line feeds
Reply: (edit)
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



Report Offensive Follow Up For Removal

Response Number 5
Name: anupam
Date: May 24, 2005 at 21:14:02 Pacific
Subject: Remove ^M and line feeds
Reply: (edit)
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.


Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Remove ^M and line feeds

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




how to setup call of duty to joytok

WindowsME / HotMail Problem

Corrupt memory

Convert fat32 to Ntfs

Best WinMo phone of 2008


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC