djkane
February 27, 2006, 7:35am
1
--------------------------------------------------------------------------------
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 substitute the combination of ^M and newline character with nothing.
I've been tryin the following
sed s/^M\n//g myFile.out
but this isn't working. Can anyone help me?
Thanks,
Darren
vino
February 27, 2006, 7:43am
2
Your duplicated thread - Substituting carriage return follwed by newline character - HELP! . Please dont duplicate. Its against the rules.
Try dos2unix myFile.out on your file to get rid of the ^M characters.
djkane
February 27, 2006, 7:51am
3
Sorry mate. First time using the forums and i wasn't sure how to move the thread as I think I posted it in the wrong place to begin with.
I will try your suggestion.
djkane
February 27, 2006, 7:54am
4
dos2unix is not a recognised command. I already remove the ^M using the sed command but i need to remove it <b> in combination with </b> the newline character.
Any other ideas?
try using dos2ux command
I just found out that on some systems it may be dos2unix
Gaurav
djkane
February 27, 2006, 8:50am
6
dos2ux does not work either
vino
February 27, 2006, 8:52am
7
Post the results of uname -a
You also mentioned that you have removed ^M using sed. What is it that you are looking for now ? Remove <b>^M</b> ?
djkane
February 27, 2006, 9:03am
8
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.
vino
February 27, 2006, 9:12am
9
When you say new line character, I assume you want two lines into 1 single line, or likewise.
Try this.
sed -e 's/^M\\n//g' file
If it doesnt work, show us a sample input and how you expect the output to be.
djkane
February 27, 2006, 9:49am
10
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.
djkane
February 27, 2006, 11:06am
11
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!!!
Ygor
February 27, 2006, 9:13pm
12
Got perl?
perl -00pe 's/\r\n//g' myFile.out
djkane
February 28, 2006, 4:34am
13
unfortunately i can't use perl mate. it's not available. it has to be done using a regular expression in UNIX.
djkane
February 28, 2006, 5:07am
14
I am returning results set from Sybase stored proc. Is there a function in Sybase that may remove the newline characters?
Ygor
February 28, 2006, 8:58pm
15
Don't know Sybase, but you should find some way to replace those characters within the stored procedure. That way you don't have to fix it afterwards. Oracle SQL has a replace() function.
Otherwise, consider using awk to remove CR+LF pairs, e.g..
awk 'sub(/\r/,""){printf $0;next}{print}' myFile.out