Remove '^M' in each line of files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove '^M' in each line of files
# 1  
Old 09-24-2008
Remove '^M' in each line of files

Hi All,

Working on AIX 5.3

we need to remove '^M' in each line of files.

could anyone please share such an experience would be appreciated.

Thanks for your time!

Regards,
# 2  
Old 09-24-2008
Do the following

1) vi the file

type this :%s/^M//g

To get ^M you hold down the CTRL key, press V then while still holding CTRL, press M.
# 3  
Old 09-24-2008
Remove '^M' in each line of files

Thnx so much bn_unx ...it works!!!

Regards,
# 4  
Old 09-24-2008
there should be an extra program to convert the files called "dos2unix"...
# 5  
Old 09-24-2008
The "^M" at line endings are a leftover from DOS/Windows: DOS encodes a line ending by a carriage return character followed by a line feed character - CR,LF.

Unix, on the other hand, ends lines with a newline character, thats all. The problem usually arises when files are being transferred (via ftp or otherwise) between the two types of systems.

To avoid it use the "ascii" mode in ftp which will change all the line endings properly for the respective system. In fact this is the difference between "binary" and "ascii" transmission mode in ftp.

I hope this helps.

bakunin
# 6  
Old 09-24-2008
use this if ur file name is "file1" and new correct file name is "file2":
tr -d '/015' file1 file2
# 7  
Old 09-24-2008
sorry for above is slighty incorrect try this will work:
tr -d '\015' < file1 > file2
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ksh: Read line parse characters into variable and remove the line if the date is older than 50 days

I have a test file with the following format, It contains the username_date when the user was locked from the database. $ cat lockedusers.txt TEST1_21062016 TEST2_02122015 TEST3_01032016 TEST4_01042016 I'm writing a ksh script and faced with this difficult scenario for my... (11 Replies)
Discussion started by: humble_learner
11 Replies

2. UNIX for Dummies Questions & Answers

How to remove fields space and append next line to previous line.?

awk 'BEGIN{FS = "Ç"} NR == 1 {p = $0; next} NF > 1 {print p; p = $0} NF <= 1 {p = (p " " $0)} END {print p}' input.txt > output.txt This is what the input data file looks like with broken lines Code: 29863 Ç890000000 Ç543209911 ÇCHNGOHG Ç000000001 Ç055 ... (4 Replies)
Discussion started by: cumeh1624
4 Replies

3. Shell Programming and Scripting

Want to remove a line feed depending on number of tabs in a line

Hi! I have been struggling with a large file that has stray end of line characters. I am working on a Mac (Lion). I mention this only because I have been mucking around with fixing my problem using sed, and I have learned far more than I wanted to know about Unix and Mac eol characters. I... (1 Reply)
Discussion started by: user999991
1 Replies

4. Shell Programming and Scripting

compare files and remove a line from a file if first column is greater than 25

my files are as follows fileA sepearated by tab /t 00 lieferungen 00 attractiop 01 done 02 forness 03 rasp 04 alwaysisng 04 funny 05 done1 fileB funnymou120112 funnymou234470 mou3raspnhdhv rddfgmoudone1438748 so all those record which are greater than 3 and which are not... (4 Replies)
Discussion started by: rajniman
4 Replies

5. UNIX for Advanced & Expert Users

Remove first line from mutiple files

How to remove the first line from multiple files and use it as source to the jobs. Only at the runtime it should remove the first line not in the file . (1 Reply)
Discussion started by: etldeveloper
1 Replies

6. Shell Programming and Scripting

remove a line in files

Hi I have 3 files and I want to remove 1 line in each file. This line correposnds to the occurrence of a specific pattern any idea how to do this in shell? thx (4 Replies)
Discussion started by: melanie_pfefer
4 Replies

7. Shell Programming and Scripting

Need to remove improperly formatted fortran output line from files, tried sed

I have been trying to remove some improperly formatted lines of output from fortran code I have been using. The problem is that I have some singularities in the math for some points that causes an incorrectly large value to be reported that exceeds the normal formating set in the code resulting in... (2 Replies)
Discussion started by: gillesc_mac
2 Replies

8. UNIX for Dummies Questions & Answers

Newbye. Help with KSH. Loop in files and remove first line

Hi everybody. Firstly, sorry for doing such a basic questions, but i have never worked with linux shells and at this moment i am trully desperated :d. I have been checkin' another posts of this forum looking for different things for mixing them and get the solution to my problem, but i have not ... (2 Replies)
Discussion started by: bringer
2 Replies

9. Shell Programming and Scripting

remove the first line of all files

I want to remove the first line of all files in a directory with .dat extension. Can any one help me on this with a small script. I want the file names to remain same . (8 Replies)
Discussion started by: dineshr85
8 Replies
Login or Register to Ask a Question