How to replace ^M present at the end of each line in a file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to replace ^M present at the end of each line in a file.
# 1  
Old 11-10-2010
How to replace ^M present at the end of each line in a file.

Hi all,

My unix admin copied my code from old server to new server. I don't know exactly how he copied by at the end of each line i see ^M appeneded. The code has more than 200 lines could you please help me how to remove it easilt instead of deleting it manually......


Thanks,
Firestar.
# 2  
Old 11-10-2010
You mean from a WIN* server to a U*X server...
Do you have dos2ux or dos2unix utility installed?
# 3  
Old 11-10-2010
@vbe

it is in solaris server.
# 4  
Old 11-10-2010
if you have Notepad++ try using Edit->EOL Conversion->UNIX Format
# 5  
Old 11-10-2010
Or:
Code:
tr -d '\r' < dosfile > unixfile

# 6  
Old 11-10-2010
Code:
us99:/export/home/vbe $ file /bin/dos2unix
/bin/dos2unix:  ELF 32-bit MSB executable SPARC Version 1, dynamically linked, stripped

# 7  
Old 11-12-2010
open the file through vi

then
%s /^M//g
use ctrl+v for the sign ^
use ctrl+m for the letter M

I hope it will work
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

2. Shell Programming and Scripting

Replace end of file with ','

Hi, I have a file with below ABC XYZ 123 I want it to look it like 'ABC','XYZ','123' I tried tr '\n' "'\,\'" but no luck Please use CODE tags as required by forum rules! (4 Replies)
Discussion started by: varun22486
4 Replies

3. Shell Programming and Scripting

With script bash, read file line per line starting at the end

Hello, I'm works on Ubuntu server My goal : I would like to read file line per line, but i want to started at the end of file. Currently, I use instructions : while read line; do COMMAND done < /var/log/apache2/access.log But, the first line, i don't want this. The file is long... (5 Replies)
Discussion started by: Fuziion
5 Replies

4. Shell Programming and Scripting

Search ad replace using begin and end of the file

Hello Friends , Please help to create script for compare and replace if not matches of set of lines . * Primary* Servername Server1 Location R201 Rack 4 *End Primary* *Secondary* Server Name Server1 IPAddress 10.24.30.10 Application Apache *End of Secondary* Above... (4 Replies)
Discussion started by: rnary
4 Replies

5. Shell Programming and Scripting

Search for a Keyword in file and replace another keyword or add at the end of line

Hi I want to implement something like this: if( keyword1 exists) then check if(keyword2 exists in the same line) then replace keyword 2 with New_Keyword else Add New_Keyword at the end of line end if eg: Check for Keyword JUNGLE and add/replace... (7 Replies)
Discussion started by: dashing201
7 Replies

6. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

7. Shell Programming and Scripting

Adding tab/new line at the end of each line of a file

Hello Everyone, I need a help from experts of this community regarding one of the issue that I am facing with shell scripting. My requirement is to append char's at the end of each line of a file. The char that will be appended is variable and will be passed through command line. The... (20 Replies)
Discussion started by: Sourav Das
20 Replies

8. Shell Programming and Scripting

simple sed question - replace from phrase to end of line

I have the following line an in input file I want to digest with sed and simple replace the bold part with a variable defined in my bash script. I can do this in several sed operations but I know there must be a way to do it in a single sed line. What is the syntax? Line in file:... (1 Reply)
Discussion started by: graysky
1 Replies

9. Shell Programming and Scripting

Replace end of line with a space

for eg: i have i/p file as: ================ i wnt to change end of line ================= my require ouput is like: i wnt to change end of line ==================== (7 Replies)
Discussion started by: RahulJoshi
7 Replies

10. Shell Programming and Scripting

sed : replace space and end-of-line

Hi ! I'm rather new with sed ... learned a lot already by googling etc ... The following script should replace all spaces and ends-of-lines with "something (see below). #!/bin/bash i=0 while read line do fam="H`printf "%06d" $i`" echo $line | sed -e 's//\t'$fam'\n/g' i=$(($i+1))... (7 Replies)
Discussion started by: jossojjos
7 Replies
Login or Register to Ask a Question