File contains ^M characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File contains ^M characters
# 1  
Old 11-07-2011
File contains ^M characters

Hello,

I tried with this command,it's working fine,file contains huge data it's not removing the control+M character
Code:
dos2unix test1.txt test2.txt

Please help me,is there any other option.

Smilie

Thanks,
Murali

---------- Post updated at 06:41 AM ---------- Previous update was at 06:40 AM ----------

File like this
Code:
1 2 3^M
3 5 6^M

Moderator's Comments:
Mod Comment This is the last warning - next infraction points will result in a ban. Please use code tags <- click the link! Read the Forum Rules!

Last edited by zaxxon; 11-07-2011 at 07:50 AM.. Reason: code tags, see PM
# 2  
Old 11-07-2011
if you want to remove ^M.You can try this..

Quote:

awk -F "^" '{print $1}' <filename
# 3  
Old 11-07-2011
i want script to write the script to implement this one.
# 4  
Old 11-07-2011
There are many ways to achieve this
1- Using vi editor
^M is DOS line break character which shows up in UNIX files when uploaded from a windows file system in ASCII format.

To remove this, open your file in vi editor and type

Code:
:%s/(ctrl-v)(ctrl-m)//g

or
Code:
:%s/^V^M//g

and press Enter key.

Important!! – press (Ctrl-v) (Ctrl-m) combination to enter ^M character, dont use “^” and M.

If anything goes wrong exit with q!.

2- Using tr command
Code:
$tr -d '\015' < file

---------- Post updated at 05:28 PM ---------- Previous update was at 05:24 PM ----------

Quote:
Originally Posted by muralikri
i want script to write the script to implement this one.
Easy use tr command snippet in a script.
# 5  
Old 11-07-2011
You can use a for loop to do this for a list of files

Quote:

for i in `cat filelist.txt`
do
::g' $i > temp.txt
done
# 6  
Old 11-07-2011
Code:
tr -d '\r' <yourfile >newfile

# 7  
Old 11-07-2011
Below command working fine...
Code:
 
tr -d '\r' <yourfile >newfile
Thanks lot

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by vbe; 11-07-2011 at 09:38 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Outputting characters after a given string and reporting the characters in the row below --sed

I have this fastq file: @M04961:22:000000000-B5VGJ:1:1101:9280:7106 1:N:0:86 GGGGGGGGGGGGCATGAAAACATACAAACCGTCTTTCCAGAAATTGTTCCAAGTATCGGCAACAGCTTTATCAATACCATGAAAAATATCAACCACACCA +test-1 GGGGGGGGGGGGGGGGGCCGGGGGFF,EDFFGEDFG,@DGGCGGEGGG7DCGGGF68CGFFFGGGG@CGDGFFDFEFEFF:30CGAFFDFEFF8CAF;;8... (10 Replies)
Discussion started by: Xterra
10 Replies

2. Linux

File conversion and removing special characters from a file in Linux

I have a .CSV file when I check for the special characters in the file using the command cat -vet filename.csv, i get very lengthy lines with "^@", "^I^@" and "^@^M" characters in between each alphabet in all of the records. Using the code below file filename.csv I get the output as I have a... (2 Replies)
Discussion started by: dhruuv369
2 Replies

3. Shell Programming and Scripting

awk script to count characters in file 1 in file 2

I need a scripting AWK to compare 2 files. file 1 and 2 are list of keywords 1 is a b c d 2 is aa aaa b bb ccc d I want the AWK script to give us the number of times every keyword in file 1 occurs in file 2. output should be a 2 (7 Replies)
Discussion started by: anhtt
7 Replies

4. Shell Programming and Scripting

sed replacing specific characters and control characters by escaping

sed -e "s// /g" old.txt > new.txt While I do know some control characters need to be escaped, can normal characters also be escaped and still work the same way? Basically I do not know all control characters that have a special meaning, for example, ?, ., % have a meaning and have to be escaped... (11 Replies)
Discussion started by: ijustneeda
11 Replies

5. Shell Programming and Scripting

Need help on getting the first few characters of a file.

Friends , I need some help in writing a shell script to get the first few characters from a file for all the lines in that file. Here is sample data inthe file. 9 JACOBS 0175 10 VENDOR_0175 11 JACOBS 0175 100 0175 I want the ouput as 9,10,11,100 It doesn't have any fixed... (7 Replies)
Discussion started by: srini02
7 Replies

6. Shell Programming and Scripting

Unix Script file to Append Characters before rows in file.

Hi Experts, I am working on HP-UX. I am new to shell scripting. I would like to have a shell script which will prefix: 1. "H|" before first row of my file and, 2. "T" for all other rows of the file. For Example - File before running the script 20100430|4123451810|218.50|TC 20100430 ... (4 Replies)
Discussion started by: phani333
4 Replies

7. Shell Programming and Scripting

Trying to remove '^M' characters from a file.

Hi guys, Hope you are all well. This is a line of data from a csv file. I have used vi and set the 'set list' option to display the trailing $ character. "01","Grocery","01006","eat Fish & Spreads"$ I have tried the following commands, but neither of them appear to be working? 1) tr... (13 Replies)
Discussion started by: Krispy
13 Replies

8. Shell Programming and Scripting

\r characters in the file

hi I copied a file to unix box from windows. When i run this file it throws error on every command written in that file. The reason is that the file contains some \r charecters that came into picture while copying the file. This could be viewed by using od -c command. My question is that... (2 Replies)
Discussion started by: infyanurag
2 Replies

9. UNIX for Dummies Questions & Answers

Rename file based on first 3 characters of data in file

I'm looking to determine if I can use a grep command to read file and rename the file based on the first 3 characters of the data in the file. An example is: Read FileA If the first 3 positions of the data in the file are "ITP", then rename the file as FileA_ITP, else if the first 3... (3 Replies)
Discussion started by: jchappel
3 Replies

10. UNIX for Dummies Questions & Answers

grepping the first 3 characters from a file

Hi I was wondering if it's possible to use a command to get the first 3 characters of a line in a text file, I tried grep but it returns the whole line but I am only interested in the first 3 characters. Is this possible with grep or I need any other command? Also is it possible deleting from... (2 Replies)
Discussion started by: g-e-n-o
2 Replies
Login or Register to Ask a Question