How to convert ^M appearing at end of line to unix newline?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to convert ^M appearing at end of line to unix newline?
# 15  
Old 08-29-2007
I have a very similar problem, so I post my question in thsi thread...

I would like to replace two characters ("CR" and ";") by a star symbol "*".

I tried this like you can see here:

tr '\013\073' '*' < filea.tab > fileb.tab

But as a result I got stars where ever a "CR" or a ";" existed, not only where they both were next to each other...

Does anybody see which mistake I make???

Thanks a lot,

Martin
# 16  
Old 08-29-2007
Quote:
Originally Posted by namishtiwari
That work sperfectlly fine,what does % signifies here.

Thanks
Namish
The % is a wild card telling s ( the substitute command ) to apply the substitution to all lines of the file. If you only wanted to do certain lines the command would be something like:
:10,35s/^M//g

where 10 is the starting line number and 35 is the ending line number.

to turn on line numbers in vi use the command:
:set nu

to turn off :
:set nonu
# 17  
Old 08-30-2007
Quote:
Originally Posted by ohagar
The % is a wild card telling s ( the substitute command ) to apply the substitution to all lines of the file. If you only wanted to do certain lines the command would be something like:
:10,35s/^M//g

where 10 is the starting line number and 35 is the ending line number.

to turn on line numbers in vi use the command:
:set nu

to turn off :
:set nonu
Thanks ohagar
# 18  
Old 08-30-2007
Hi,

I have one text file(that file file has pipe line (|) seperate file), i want to cut the 16th and 81st column from the text file using the below commands

Input file is:
==========
file_header|GEES-EU|343|2007-08-29T07:10:51|SSPF|12|2008|0|0|SSS||

invoice_header|39478-198192-2|250489|BRIDGEWATER108|2007-08-28T00:00:00|1|STANDARD|Receipt Invoice automatically created on 29-AUG-07|ERS|USD|USD|1|0|0|1|1613314|0|0|01 75 2.00/15|2007-08-28T00:00:00|75|2007-11-11T00:00:00|.02|2|15|2007-09-12T00:00:00|CHECK||30.391998.00000.000.00.00.000000.00000.000|N|||N|2007-08-28T00:00:00|2007-08-29T00:00:00|||1||||||||SSPF|||||||||||||DAT|||||||||||||||||||||343|GEES-EU||N||2007-08-28T00:00:00|1||||||2007-08-28T00:00:00|||||Y||NOT REQUIRED|Validated||manjunath.nagasomasundaram@ge.com|||||||||||||SSPF|SSPF|0||||||||||||||
invoice_detail|39478-198192-2|2|ITEM|1|1|1|AUG-07|17.121504.45820.000.00.00.000000.00000.000|Advertising campaign services|1613314|1|11456689|4796888||236029302|0|1|1|1|2007-08-28T00:00:00|N|U|N|N|||||||A|N||||||||||||||||ERS-SSPF|||||10512|||||||||E||||||||||||||||||343|GEES-EU||N|N||||||||||||||||||||||||||||||||||||||ITEM_TO_PO|||||5938078||||N|N|Y|N|||||||||||Each||27663 13||||||N|||||501456183||ERS-SSPF||||||Nagasomasundaram, Manjunath||||||||||manjunath.nagasomasundaram@ge.com|manjunath.nagasomasundaram@ge.com|GE Hungary ZRt. - Engine Service|H-2112 HU|VERESEGYHAZ|HU||US||8210180100|SSPF

po_number=`echo $text_file|cut -d"|" -f16`
echo $po_number
orgid=`echo $text_file|cut -d"|" -f81`
echo $orgid

But my script is not giving any outputs. i have tried with above commands its cut upto 10 column.

what is the problem? any one help me.

Regards,
Siva.P
Bangalore
# 19  
Old 08-31-2007
Quote:
Originally Posted by matrixmadhan
that's a single character

and to display that on the terminal you need to type ctrl v followed by ctrl M
If you are using vi, the [CTRL][V] tells the computer NOT to execute the next command ([CTRL][M] - which is a new line) but to write it or in this case to replace it. If you are using vim in Windows, you have to use [CTRL][Q] instead of [CTRL][V] since [CTRL][V] in windows is mapped to paste.
The [CTRL] appears as '^' in the file. Window's programs end each line with two characters: <new-line><carriage-return>, whereas unix ends a line with only one character <new-line>.
I believe a new-line character is [CTRL][L] and the carriage return is [CTRL[M].
# 20  
Old 08-31-2007
Quote:
Originally Posted by psiva_arul
po_number=`echo $text_file|cut -d"|" -f16`
Try:

po_number=`cat text_file | cut -d"|" -f16` ...
# 21  
Old 09-01-2007
Quote:
Window's programs end each line with two characters: <new-line><carriage-return>
Am not sure of this but I doubt this. !

Does that mean,

for a file with 10 bytes in first line
and 8 bytes in second line.

Then is the total size of the file : 10 + ( 1 + 1 ) ( 1 CR + 1 NL )
+
8 + ( 1 ) ( 1 NL )
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to convert \n character to newline in UNIX.

I have a variable like below: str1="10.9.11.128\n-rwxr-xr-x user1 2019-12-29 17:53 /var/branch/custom/tg.xml 286030210\n10.9.12.129\n-rwxr-xr-x user1 2019-12-29 17:53 /app/branch/custom/tg.xml 286030210\n10.9.20.130\n-rwxr-xr-x user1 2019-12-29 17:53 /web/branch/custom/tg.xml 286030210" I... (8 Replies)
Discussion started by: mohtashims
8 Replies

2. Shell Programming and Scripting

No newline at end of file

Hello all, I have maybe a simple Problem - but I do not know to handle it. All what I want, is to write a line to file without a newline at the end. It works with "echo -n" for all lines, but not for the last one. At the end of the file is always a "0a" (hex) My small script: ... (10 Replies)
Discussion started by: API
10 Replies

3. Shell Programming and Scripting

Appending newline character End of File

Hi Gurus, Need help. I'm a beginner in Unix. I have a requirement, need to add or append newline (\n) character in file. Sample Data: 1|Main|Test|~# 2|Main|Hello|~# 3|Main|Unix|~# 4|Main|File|~#Output: 1|Main|Test|~# 2|Main|Hello|~# 3|Main|Unix|~# 4|Main|File|~#\n -- append only... (13 Replies)
Discussion started by: Gouri Solleti
13 Replies

4. Shell Programming and Scripting

How to add newline character at end of file?

Hi All, I have following piece of code in UNIX C Shell script and I want to add one more command which can add newline at the end of file only if there is no newline character exists. foreach file (`ls $dd_PLAYCARD_EDI_IN`) if ( -f $dd_PLAYCARD_EDI_IN/${file} ) then cat -n... (4 Replies)
Discussion started by: jnrohit2k
4 Replies

5. Shell Programming and Scripting

NULL in between, at begining or at end of line - convert to space

How to replace null with space? I want to make each line with 80 characters. If any line contains only 5 characters and remaining is null, then i want to make it as 80 characrets where 5 is original characters and remaining 75 characters will be null.. NULL can come in between the line,... (3 Replies)
Discussion started by: Amit.Sagpariya
3 Replies

6. Shell Programming and Scripting

How to enter a newline after every XML tag end?

Hi Guyz, I have an XML message in following format: I want my contents to be formatted in following order: i.e. I want a newline after every XML tag end. How to do this? Thnx in advance. (5 Replies)
Discussion started by: DTechBuddy
5 Replies

7. Shell Programming and Scripting

SED to convert ~ in a file to newline

Hi, I have a .txt file which has a tilde(~) in it. All that I want is to break into a newline whenever there is an occurence of '~'. I have tried SED to do that but I could not succeed. I would appreciate if I can get a shell script(ksh) for this problem real quick. Thanks in advance. ... (5 Replies)
Discussion started by: ntekupal
5 Replies

8. Shell Programming and Scripting

How to remove a newline character at the end of filename

Hi All, I have named a file with current date,time and year as follows: month=`date | awk '{print $2}'` date=`date | awk '{print $3}'` year=`date | awk '{print $6}'` time=`date +%Hh_%Mm_%Ss'` filename="test_"$month"_"$date"_"$year"_"$time".txt" > $filename The file is created with a... (2 Replies)
Discussion started by: amio
2 Replies

9. Shell Programming and Scripting

Append newline at the file end

Hi All, Is there any way to append a newline character at the end of a file(coma-separated file), through shell script? I need to check whether newline character exists at the end of a file, if it does not then append it. Regards, Krishna (1 Reply)
Discussion started by: KrishnaSaran
1 Replies

10. UNIX for Advanced & Expert Users

Deleting UNIX End of Line Chachracter \000

Hi, I have this file which has some octal NULL characters (\000). I need to replace these characters with an ASCII NULL. I've tried using Perl, the UNIX tr command.. History of this I received a COBOL generated file, ran the od command to convert to a xxx byte per record file. Now,... (3 Replies)
Discussion started by: uchachra
3 Replies
Login or Register to Ask a Question