Removing control-Ms (^M)


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
Removing control-Ms (^M)

Anyone know how to remove ^M's from a text file using sed command?
# 2  
You just have to remove the last character since its the last ...
Code:
sed -e 's/.$//g' file > file2

# 3  
No, i'm returning a record from the DB, and one of the fields has ^Ms contained within it. This means it won't be the last character unfortunately.
# 4  
Code:
sed 's/^M// file    # Press Ctrl-V then Ctrl-M to get ^M

# 5  
for anyone that wants to know i found a different piece of code to use

#*********************************************************
# CHANGE LOG:
# DATE PERSON COMMENT
# ----------- ----------- -----------
# 28 FEB 2006 DARREN KANE CREATED
#*********************************************************

FILE=$1

/bin/tr -d '\015' < $FILE > t.$$
/bin/mv -f t.$$ $FILE
# 6  
unix2dos
dos2unix
# 7  
or, dependant on your system

ux2dos
dos2ux
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #580
Difficulty: Easy
A file is a block of data used for storing information.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Removing PATTERN from txt without removing lines and general text formatting

Hi Everybody! First post! Totally noobie. I'm using the terminal to read a poorly formatted book. The text file contains, in the middle of paragraphs, hyphenation to split words that are supposed to be on multiple pages. It looks ve -- ry much like this. I was hoping to use grep -v " -- "... (5 Replies)
Discussion started by: AxeHandle
5 Replies

2. UNIX for Dummies Questions & Answers

Removing the ^M control character

I've got a file where each line is separated by ^M characters. I want to be able to cat the file without those lines. When I cat the file now what I see are blank lines. However, the blank lines are actually ^M characters; when I open the file with vi they show up. X38888 No No No... (7 Replies)
Discussion started by: newbie2010
7 Replies

3. Shell Programming and Scripting

Help in removing control M and Line feed in output file.

Hi All, In my output file i am getting control m character and also the line feeds at different places and with different combinations, the content of the file is supposed to be in a single line but if there is a line feed in between then from there onwards it's going into new line. I tried... (7 Replies)
Discussion started by: Bipin Kumar
7 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Removing control-m characters from shell script

Hi All, I need to remove control m character from a file. Steps which i am doing in shell script are: 1) We are comparing the header of the file to the database table header Here the file header has control-m characters. How do i remove it. Please help. Below are the steps i am using,... (12 Replies)
Discussion started by: abhi_123
12 Replies

5. Shell Programming and Scripting

Removing special characters - Control M

I have developed a small script to remove the Control M characters that get embedded when we move any file from Windows to Unix. For some reason, its not working in all scenarios. Some times I still see the ^M not being removed. Is there anything missing in the script: cd ${inputDir}... (7 Replies)
Discussion started by: vskr72
7 Replies

6. Hardware

control card

Our unix server failed to restart after we did a monthly "hard shutdown". We replaced the control card in the motherboard with a card from another machine. The system would then pull up but we could not access any information. I need to find this SCSI board. Apparently, I HAVE to have this one. ... (0 Replies)
Discussion started by: kmelton
0 Replies

7. Shell Programming and Scripting

Removing Control M character

Hi, I'm using MKS tool kit to execute KSH on windows and samba to move files to unix from windows. My script is appending header record for the data file. I'm using echo "$header" > $SambaFilename cat $windowsfile >> $SambaFilename But after execution of script ,The file in Unix... (2 Replies)
Discussion started by: ammu
2 Replies

8. Shell Programming and Scripting

Job control

Hello, What is the best way to control the running of scripts? For example, i have a k1.ksh script java pgm that checks to make sure that the file counts in a particular directory are equal to a total file count value in a control file updated from my PC. If i run this k1.ksh script and... (3 Replies)
Discussion started by: bobk544
3 Replies

9. UNIX for Advanced & Expert Users

New to Control-M

Hi, I am very new to Control-M . If anywone know about the global conditions in Control-M. (5 Replies)
Discussion started by: oraclenerd
5 Replies

10. Programming

Identifying and removing control characters in a file.

What is the best method to identify an remove control characters in a file. Would it be easier to do this in Unix or in C. (0 Replies)
Discussion started by: oracle8
0 Replies

Featured Tech Videos