Remove a ^M character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove a ^M character
# 1  
Old 07-14-2009
Remove a ^M character

Hi,
I'd like to ask for some help with the following:

I've cut a couple of columns of file1 to create file2 with the following code:
cur -f 1,3,8 file1 > file2

Then I need to transfer file 2 from UNIX to Windows and use it further.
Unfortunatelly, for some reason the line is displayed as two fields in one line and then the third one is in separate new line. Something like this:
filed1 filed3
filed8
filed1 filed3
filed8
etc

When I tried to look at the file in Unix the the code:

less-l file2

it write this:

filed1 filed3^M filed 8

I tried to get rid of the "^M" by the following code:

replace "^M" " " -- file2

But nothing happens.

Could anybody help me to get rid of it and have mine three fields in one line, please?

Your help will be grteatelly appretiated!

Many thanks in advance!
# 2  
Old 07-14-2009
Hello!

This question has been asked and answered numerous times!

Per forum rules, and the benefit of all users, please search the forums before posting a question.

You can easily search the forums using our internal Google search engine or our advanced internal search engine. You can also search our huge UNIX and Linux database by user generated tags or search the database for unanswered questions and provide an answer.

Thank you.

The UNIX and Linux Forums
# 3  
Old 07-14-2009
I apologize!
# 4  
Old 07-14-2009
One way to remove the carriage-returns:

Code:
cat filename | tr -d '\r' > new_filename

To check your original files to see whether that is where the carriage-return came from.
The carriage returns show as "\r" , the line feeds show as "$".

Code:
sed -n l original_filename

The text file line terminator in MSDOS is two characters "cr/lf", wheras on unix it is one character "lf". When transferring files to/from MSDOS systems it is important to know this and to either convert the file in transit (e.g. with text file FTP) or to convert the file on one of the servers.

Last edited by methyl; 07-14-2009 at 03:17 PM.. Reason: Layout
# 5  
Old 07-14-2009
Many thanks Methyl!!!!!
You can not imagine how much easier you made my life!!!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove character \r and \n in awk

Hi Everybody: I need your help, please... I have this file *.txt 0000 | 16010201 22000000 67892000 00000000 00000000 00000100 72246681 28E08236 | ~~~~"~~~g~ ~~~~~~~~~~~~~r$f~(~~6 | 0020 | 10476173 90010100 10000000 00000001 05000226 17163011 12442212 48140484 |... (2 Replies)
Discussion started by: solaris21
2 Replies

2. Shell Programming and Scripting

How to remove newline character if it is the only character in the entire file.?

I have a file which comes every day and the file data look's as below. Vi abc.txt a|b|c|d\n a|g|h|j\n Some times we receive the file with only a new line character in the file like vi abc.txt \n (8 Replies)
Discussion started by: rak Kundra
8 Replies

3. Shell Programming and Scripting

Remove last newline character..

Hi all.. I have a text file which looks like below: abcd efgh ijkl (blank space) I need to remove only the last (blank space) from the file. When I try wc -l the file name,the number of lines coming is 3 only, however blank space is there in the file. I have tried options like... (14 Replies)
Discussion started by: Sathya83aa
14 Replies

4. Shell Programming and Scripting

remove the first and last character of a string

How can i remove the first and last character of strings like below: "^^^613*" "admt130" "^^^613*" "123456" "adg8484" "DQitYV09dh1C" Means i wanna remove the quotes(""). Please help (17 Replies)
Discussion started by: proactiveaditya
17 Replies

5. Shell Programming and Scripting

Remove last character from filename

Hi All, I have different type of file (.txt,.csv,.xml) format in my current directory. My requirement is that I need to remove the last character from the file format. Example count.txt$ csp_rules.csv^ Date.xml~ Need Output: count.txt csp_rules.csv Date.xml How to do that?.... (5 Replies)
Discussion started by: suresh01_apk
5 Replies

6. Shell Programming and Scripting

How to remove first 2 character from file name

Hi All Please help me to remove the first 2 character from the file name. files are like this $ ls 12aman file 13atul si 56rana se I want to remove the first 2 char which are numbers. I want the o/p like thus aman file atul si rana se (8 Replies)
Discussion started by: atul9806
8 Replies

7. HP-UX

How to remove new line character and append new line character in a file?

Hi Experts, I have data coming in 4 columns and there are new line characters \n in between the data. I need to remove the new line characters in the middle of the row and keep the \n character at the end of the line. File is comma (,) seperated. Eg: ID,Client ,SNo,Rank 37,Airtel \n... (8 Replies)
Discussion started by: sasikari
8 Replies

8. UNIX for Dummies Questions & Answers

How to remove \ character

Dear Members, I have a file which is a single line file. It has "\" character and i need to replace this character with a new line character. How can we do this? I tried with sed but it did not work. sed 's//"\n"/g' t1 > t2Thanks Sandeep (3 Replies)
Discussion started by: sandeep_1105
3 Replies

9. UNIX for Advanced & Expert Users

To remove new line character

Hi, I am facing one interesting problem : I have a file which contains data like this 459,|1998-11-047|a |b |c \n efg | d|e | \n 459,|1998-11-047|a \n c|b |c \n efg | d|e | \n Basically what I have to do is , I have to remove all \n which is coming ( enclosed ) in between... (7 Replies)
Discussion started by: shihabvk
7 Replies

10. Shell Programming and Scripting

Remove last character of a term

Hi All, I have a few terms with a comma as the last character. Can any experts show me how to remove the last character? Note the the length of the term is not fix. Input: 1, 2, 12, 14, 103, 198, 3006, Output, 1 (6 Replies)
Discussion started by: Raynon
6 Replies
Login or Register to Ask a Question