Removing Control M character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing Control M character
# 1  
Old 12-03-2008
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 conatins Control M character at the end of header record. How to eliminate this character.

Please advice!
# 2  
Old 12-03-2008
Code:
# IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format.
sed 's/.$//'               # assumes that all lines end with CR/LF
sed 's/^M$//'              # in bash/tcsh, press Ctrl-V then Ctrl-M
sed 's/\x0D$//'            # works on ssed, gsed 3.02.80 or higher
# IN UNIX ENVIRONMENT: convert Unix newlines (LF) to DOS format.
sed "s/$/`echo -e \\\r`/"            # command line under ksh
sed 's/$'"/`echo \\\r`/"             # command line under bash
sed "s/$/`echo \\\r`/"               # command line under zsh
sed 's/$/\r/'                        # gsed 3.02.80 or higher
# IN DOS ENVIRONMENT: convert Unix newlines (LF) to DOS format.
sed "s/$//"                          # method 1
sed -n p                             # method 2

# 3  
Old 12-03-2008
Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. Shell Programming and Scripting

control M character in unix file

in a file we are getting control character in a file , is there any way that they can be removed once we have the file for eg. BEGIN-PROCEDURE INITIALIZE ^M LET #row_count = 0^M ^M ^M (2 Replies)
Discussion started by: lalitpct
2 Replies

6. UNIX for Dummies Questions & Answers

Need help removing last character of every line if certain character

I need help removing the last character of every line if it is a certain character. For example I need to get rid of a % character if it is in the last position. Input: aaa% %bbb ccc d%dd% Output should be: aaa %bbb ccc d%dd I tried this but it gets rid of all of the % characters.... (5 Replies)
Discussion started by: raptor25
5 Replies

7. Shell Programming and Scripting

unwanted control character in the input

Hi Shell Scripting Experts, I have a shell script running daily on a remote machine through ssh. To avoid the trouble of restarting the script when ssh disconnects, I use screen (a unix tool) and run the script within a screen session. What this script does is to ask the user to input y or n... (2 Replies)
Discussion started by: jeff_cen
2 Replies

8. UNIX for Dummies Questions & Answers

Control character in a file

Hi All, I am looking for a solution to capture any ASCII control character in a file ( where the ASCII control character is in decimal value from 0 to 31 and 127 ( Hex value from 00 to 1F and 7F ) ) by returning any affected lines. The intended good file should contain "ASCII printable... (5 Replies)
Discussion started by: cursive
5 Replies

9. Shell Programming and Scripting

Removing control-Ms (^M)

Anyone know how to remove ^M's from a text file using sed command? (6 Replies)
Discussion started by: djkane
6 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
Login or Register to Ask a Question