Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Substitute \n with carriage return

Shell Programming and Scripting


Closed    
 
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: 24 May 2017, 1:11 PM EDT
Location: Galactic Empire
Posts: 3,544
Thanks: 251
Thanked 1,288 Times in 1,210 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 May 2017, 11:32 AM EDT
Location: Switzerland - GE
Posts: 6,412
Thanks: 273
Thanked 538 Times in 500 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: 24 May 2017, 1:11 PM EDT
Location: Galactic Empire
Posts: 3,544
Thanks: 251
Thanked 1,288 Times in 1,210 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: 24 May 2017, 1:11 PM EDT
Location: Galactic Empire
Posts: 3,544
Thanks: 251
Thanked 1,288 Times in 1,210 Posts

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

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
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 04:12 PM.