[Solved] Removing control-m characters from shell script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [Solved] Removing control-m characters from shell script
# 1  
Old 11-11-2012
[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, but is not working out.

Code:
v_header=`sed 1q $v_sftphomedir/$v_finalsourcefile`
echo $v_header |tr -d '\015' > v_avilableheader

or
Code:
sed 's/^M//g' $v_header


Please help.

Last edited by Scott; 11-11-2012 at 01:10 PM.. Reason: Code tags
# 2  
Old 11-11-2012
dos2unix , unix2dos

Quote:
Originally Posted by abhi_123
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, but is not working out.

v_header=`sed 1q $v_sftphomedir/$v_finalsourcefile`
echo $v_header |tr -d '\015' > v_avilableheader
or
sed 's/^M//g' $v_header Smilie


Please help.
Hello,

If you copy a file created or modified in Windows or DOS to a Linux/Unix file system, you sometimes find ^M characters at the end of each line.

try to use dos2unix / unix2dos.

Regards

Last edited by bdittmar; 11-11-2012 at 12:13 PM.. Reason: Add line
# 3  
Old 11-11-2012
Try:-
Code:
 
sed 's/'"$(printf '\015')"'//g' input_file > output_file

# 4  
Old 11-11-2012
is it a generic code to remove control M characters in a sample file

Code:
 
sed 's/'"$(printf '\015')"'//g' input_file > output_file

# 5  
Old 11-11-2012
i just want to replace it in my header variable which has the file header content take form file and not entire file.
Its just a variable in shell script which has the header value and not a filename. how to remove from that variable which is having control-m character.

How do i do this. PLease help.Smilie
# 6  
Old 11-11-2012
Code:
sed 's/^'$v_header''"$(printf '\015')"'*//g' input_file > output_file


Last edited by Yoda; 11-11-2012 at 12:42 PM..
# 7  
Old 11-11-2012
when i do the steps mentioned above i get the below error :
Code:
sed 's/'"$(printf '\015')"'/'$v_header'/g' $v_header > Newheader
Can't open "MEMBER"|"MEMBERDESC"|"LEVEL0"|"LEVEL1"|"LEVEL1DESC"|"

Smilie

Last edited by Scott; 11-11-2012 at 01:11 PM.. Reason: Code tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[solved]removing characters from a mass of file names

I found a closed thread that helped quite a bit. I tried adding the URL, but I can't because I don't have enough points... ? Modifying the syntax to remove ! ~ find . -type f -name '*~\!]*' | while IFS= read -r; do mv -- "$REPLY" "${REPLY//~\!]}"; done These messages are... (2 Replies)
Discussion started by: rabidphilbrick
2 Replies

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

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

4. Shell Programming and Scripting

Version Control Through the Shell Script

Version Control Through the Shell Script Hi Guys, Apologize for the big request, please take some time and read it completely... This is Very important for me, and ur help is Very much Appriciated. I want to maintain the Version control to all my scripts running in Production server, I am... (6 Replies)
Discussion started by: Anji
6 Replies

5. Shell Programming and Scripting

Control browser from shell script

I have a browser running in a separate virtual terminal and would like to be able to send shortcut codes (e.g. ctrl+A) to the browser (and have it react) from a bash script in a separate virtual terminal. I need to keep the script in the separate virtual terminal. (2 Replies)
Discussion started by: slak0
2 Replies

6. Shell Programming and Scripting

help removing characters for output file in shell script

hi i'm new to shell scripts and have a small problem i am running a batch converter that returns all flash .flv files in a directory and create a png image from each one the problem i have is the $1 variable , its ok on the first call but on the secound call $1.png , i have extra... (1 Reply)
Discussion started by: wingchun22
1 Replies

7. Shell Programming and Scripting

How to Control Cronjobs using Shell Script??

Hi All, Now i am running the 3 oracle procedures one by one manually. Query: If 1st Procedure OUT_PUT is Success, then call 2nd Procedure. If 2nd Procedure OUT_PUT is Success, then call 3rd Procedure. If 1st Procedure is failed, then no need of calling the other ... (8 Replies)
Discussion started by: hanu_oracle
8 Replies

8. Shell Programming and Scripting

control over shell script

Hi.. I have a perl program that uses "system" to execute a shell script called startengine. The script "startengine" itself calls a lot of other smaller scripts to setup the engine etc. It finally has to execute ./engine which is another shell script which is long and takes a long time to... (3 Replies)
Discussion started by: JLJ
3 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