Substituting carriage return followed by newline character - HELP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Substituting carriage return followed by newline character - HELP
# 8  
Old 02-27-2006
uname -a gives...

AIX carnowen 2 5 005AA72F4C00

I need to remove a combination of ^M and newline character.

i tried...

sed s/^M\n//g but this does not work :'(

thanks for your help mate.
# 9  
Old 02-27-2006
When you say new line character, I assume you want two lines into 1 single line, or likewise.

Try this.

Code:
sed -e 's/^M\\n//g' file

If it doesnt work, show us a sample input and how you expect the output to be.
# 10  
Old 02-27-2006
text file is like follows (this is how it would look using vi)

line1field1 line1field2 line1field3 line1field4 line1field5
line2field1 line2field2 line2field3 line2field4 line2field5
line3field1 line3field2 line3field3^M
line3field4 line3field5
line4field1 line4field2 line4field3 line4field4 line4field5
line5field1 line5field2 line5field3 line5field4 line5field5

I need this to become


line1field1 line1field2 line1field3 line1field4 line1field5
line2field1 line2field2 line2field3 line2field4 line2field5
line3field1 line3field2 line3field3 line3field4 line3field5
line4field1 line4field2 line4field3 line4field4 line4field5
line5field1 line5field2 line5field3 line5field4 line5field5

I tried the sed command you used in your previous post but this hasn't worked. Again, thanks for your help friend.
# 11  
Old 02-27-2006
maybe there's a different way of representing newline characters when using sed??

if i use

sed -e s/^M//g myFile.out

then the ^M is removed. All i need to do now is try and get line 3 in the above example onto one line!!

Anyone got any ideas?? This is doin' my 'ead in!!!
# 12  
Old 02-27-2006
Got perl?

perl -00pe 's/\r\n//g' myFile.out
# 13  
Old 02-28-2006
unfortunately i can't use perl mate. it's not available. it has to be done using a regular expression in UNIX.
# 14  
Old 02-28-2006
I am returning results set from Sybase stored proc. Is there a function in Sybase that may remove the newline characters?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Remove carriage return

I need to remove the carriage return comes inbetween the record. Need to have CR only at the end. I used the below command. tr -d '\n' < filewithcarriagereturns > filewithoutcarriagereturns But its removing all the CR and giving one line output. Input File: 12345 abcdegh... (11 Replies)
Discussion started by: srvn_saru
11 Replies

2. Shell Programming and Scripting

Substitute \n with carriage return

Hello all, I've a flat file in the following format: 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 (8 Replies)
Discussion started by: sethmj
8 Replies

3. Shell Programming and Scripting

2 carriage return within a record

Hi all, need your help in replacing carriage return in a record. Input: col1|col2|col3|col4|col5|col6|col7|col8|col9|col10 1|aa|bb|cc|dd|eee eee|ff|ggggg|hh hhh|iii 2|zz|yy|xx|ww|vv|uu|tt|ss|rr Output: col1|col2|col3|col4|col5|col6|col7|col8|col9|col10... (12 Replies)
Discussion started by: agathaeleanor
12 Replies

4. Shell Programming and Scripting

Help substituting text in a file having a single line but no newline char

Hello, Need help substituting a particular word in a file having a single line but no newline character at the end. I was trying to use sed but it doesn't work probably because there is no newline char at the end of the line. $ cat hlq_detail /outputs/alvan23/PDFs/bills $ cat... (5 Replies)
Discussion started by: Shan_u2005
5 Replies

5. UNIX for Dummies Questions & Answers

carriage return and linefeed

hi can anyone please tell me the difference between carriage return, linefeed and newline ? (2 Replies)
Discussion started by: streetfi8er
2 Replies

6. Shell Programming and Scripting

carriage return or funky character stuck in my variables - help :)

My variables contain carriage returns... or something. Here is the line in my xml file of interest: <tmp>72</tmp> And here is the line that extracts the 72 from it: REAL=`grep '<tmp>' test.xml | sed -e 's/^ *<tmp>//' -e 's/<\/tmp>//' -re 's/(N|n|A|a|\/)/U/g'`If echo the variable it... (5 Replies)
Discussion started by: audiophile
5 Replies

7. UNIX for Dummies Questions & Answers

Substituting carriage return follwed by newline character - HELP!

Hi All I have a field being returned from the DB that when opened in Vi shows a ^M before the rest of the field is displayed on the next line. I need it so that the only newline character is the end of the line since I need to transform my file into an Excel report. Thus my idea is to... (1 Reply)
Discussion started by: djkane
1 Replies

8. Shell Programming and Scripting

Dont want carriage return

I have observed with print & echo, they produce carriage return <CR> or newline, after they display string next to them. Is there anyway to avoide these <CR> after the intended string is displayed? (3 Replies)
Discussion started by: videsh77
3 Replies

9. Shell Programming and Scripting

sed removing carriage return and newline

Hi, I'm not very familiar with unix shell. I want to replace the combination of two carriage returns and one newline with one carriage return and one newline. I think the best way to do this is to use sed. I tried something like this: sed -e "s#\#\#g" file.txt but it doesn't work. Thanx... (2 Replies)
Discussion started by: mored
2 Replies

10. Shell Programming and Scripting

Capture carriage return.

I try to test the carriage return in a variable. $ LENGTH=`expr $VARIABLE : ".*"` will return the length of the variable. But this doesn't work if $VARIABLE has zero length. Any help will be well appreciated. Thanks in advance. Giovanni (4 Replies)
Discussion started by: gio123bg
4 Replies
Login or Register to Ask a Question