Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Substitute \n with carriage return

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 06-21-2013
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 30 July 2015, 6:29 PM EDT
Location: Galactic Empire
Posts: 3,420
Thanks: 240
Thanked 1,223 Times in 1,149 Posts

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

Sponsored Links
    #3  
Old Unix and Linux 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 Unix and Linux 06-21-2013
vbe's Unix or Linux Image
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 24 July 2015, 5:57 PM EDT
Location: Switzerland - GE
Posts: 6,072
Thanks: 197
Thanked 460 Times in 429 Posts
Are you sure your file is not DOS format?
Sponsored Links
    #5  
Old Unix and Linux 06-21-2013
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 30 July 2015, 6:29 PM EDT
Location: Galactic Empire
Posts: 3,420
Thanks: 240
Thanked 1,223 Times in 1,149 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 Unix and Linux 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 Unix and Linux 06-21-2013
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 30 July 2015, 6:29 PM EDT
Location: Galactic Empire
Posts: 3,420
Thanks: 240
Thanked 1,223 Times in 1,149 Posts

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

Sponsored Links
Closed Linux or Unix Question

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
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 01:02 AM.