Unix/Linux Go Back    


AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

How to remove ^M from the EOL?

AIX


Tags
aix, unix

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-02-2013   -   Original Discussion by mrn6430
mrn6430's Unix or Linux Image
mrn6430 mrn6430 is offline
Registered User
 
Join Date: May 2011
Last Activity: 28 September 2017, 1:14 PM EDT
Location: USA
Posts: 114
Thanks: 23
Thanked 0 Times in 0 Posts
How to remove ^M from the EOL?

The only way I know of is manually as follows:
To remove for example ^M from a file:
- vi the file name that has ^M at the end of each line.
- Hit <Esc>
- Type :g/
- Hold the CNTRL key and press V and M then release the CNTRL key At the buttom you should see this by now: :g/^M
- Then type /s///g at the end of the line. You should see this g/^M/s///g now.
- Hit <enter>. All ^M at the end of each line should go away by now.
- Save the file and exit.

Good luck
Sponsored Links
    #2  
Old Unix and Linux 04-02-2013   -   Original Discussion by mrn6430
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 19 November 2017, 9:17 PM EST
Location: Galactic Empire
Posts: 3,601
Thanks: 253
Thanked 1,315 Times in 1,232 Posts
That ^M control-M is a CR (carriage return).

As per ASCII table the octal code for CR is 015. So we can remove it using below sed:

Code:
sed 's/'"$(printf '\015')"'$//g' inputfile > outputfile

Sponsored Links
    #3  
Old Unix and Linux 04-02-2013   -   Original Discussion by mrn6430
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 19 November 2017, 9:29 AM EST
Location: Aachen, Germany
Posts: 11,625
Thanks: 320
Thanked 3,617 Times in 3,322 Posts
Knowing that AIX is a bit tight when it comes to generic and versatile tools, I still would like to propose any of recode, iconv, and dos2unix, which all can do more than just deleting the ^M at EOL. tr would help as well.
    #4  
Old Unix and Linux 04-02-2013   -   Original Discussion by mrn6430
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 17 November 2017, 9:25 PM EST
Location: Saskatchewan
Posts: 22,512
Thanks: 1,151
Thanked 4,273 Times in 3,946 Posts
tr should be present on any UNIX, while dos2unix is rare.


Code:
tr -d '\r' < inputfile > outputfile

Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to insert EOL? mrn6430 Linux 5 04-02-2013 01:33 PM
Delete to eol after pattern with sed ppaprota Shell Programming and Scripting 2 11-19-2012 05:01 PM
Remove EOL selectively praveenbvarrier Shell Programming and Scripting 5 11-17-2011 05:29 AM
Sendmail, EOL not effecting cv_pan Shell Programming and Scripting 1 12-23-2008 02:21 AM
Lookup value in file and Append new value at EOL kixazz2529 Shell Programming and Scripting 4 08-25-2008 02:35 PM



All times are GMT -4. The time now is 05:37 AM.