Substitute \n with carriage return | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Substitute \n with carriage return

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-21-2013
sethmj sethmj is offline
Registered User
 
Join Date: Jan 2012
Last Activity: 21 June 2013, 12:21 PM EDT
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Substitute \n with carriage return

Hello all,


I've a flat file in the following format:

PHP Code:
AB\001\CDED\001\ABC\001\nEG\001\HIJF\001\EFG\001\nHI\003\HIUL\003\HIJ\003 

And I want to substitute \n with the carriage return. Any help is appreciated!

Regards,
- Seth
Sponsored Links
    #2  
Old 06-21-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 20 August 2014, 1:27 PM EDT
Location: Galactic Empire
Posts: 3,361
Thanks: 230
Thanked 1,195 Times in 1,124 Posts

Code:
tr '\n' '\r' < input > output

Sponsored Links
    #3  
Old 06-21-2013
sethmj sethmj is offline
Registered User
 
Join Date: Jan 2012
Last Activity: 21 June 2013, 12:21 PM EDT
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Hi, Thank-you for the response.

Its actually throwing out a control-M at the end of the file.


PHP Code:
AB\001\CDED\001\ABC\001\nEG\001\HIJF\001\EFG\001\nHI\003\HIUL\003\HIJ\003^
    #4  
Old 06-21-2013
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 20 August 2014, 3:34 PM EDT
Location: Switzerland - GE
Posts: 5,634
Thanks: 152
Thanked 387 Times in 366 Posts
Are you sure your file is not DOS format?
Sponsored Links
    #5  
Old 06-21-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 20 August 2014, 1:27 PM EDT
Location: Galactic Empire
Posts: 3,361
Thanks: 230
Thanked 1,195 Times in 1,124 Posts
Quote:
Originally Posted by sethmj View Post
Its actually throwing out a control-M at the end of the file.
That ^M character is a Carriage return
Sponsored Links
    #6  
Old 06-21-2013
sethmj sethmj is offline
Registered User
 
Join Date: Jan 2012
Last Activity: 21 June 2013, 12:21 PM EDT
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
But I want to replace
Code:
\n

to carriage return. I was hoping to get the output something like this:

PHP Code:
AB\001\CDED\001\ABC\001
EG
\001\HIJF\001\EFG\001
HI
\003\HIUL\003\HIJ\003 

Sponsored Links
    #7  
Old 06-21-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 20 August 2014, 1:27 PM EDT
Location: Galactic Empire
Posts: 3,361
Thanks: 230
Thanked 1,195 Times in 1,124 Posts

Code:
awk '{gsub(/\\n/,RS)}1' file

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search_Replace with a Carriage Return leepet01 Shell Programming and Scripting 5 11-02-2011 12:19 PM
2 carriage return within a record agathaeleanor Shell Programming and Scripting 12 08-19-2011 05:49 AM
carriage return and linefeed streetfi8er UNIX for Dummies Questions & Answers 2 06-24-2009 08:54 PM
Dont want carriage return videsh77 Shell Programming and Scripting 3 12-16-2004 08:26 PM
Capture carriage return. gio123bg Shell Programming and Scripting 4 12-15-2003 09:21 AM



All times are GMT -4. The time now is 12:21 AM.