Script to Remove Garbage Character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to Remove Garbage Character
# 1  
Old 03-27-2006
Script to Remove Garbage Character

Hello,

Whenever I transfer files between machines, I find a garbage character (^M) being appended to the end of every line of the file.

Can you suggest a script wherein I can eliminate the garbage character.

I tried sed 's/^M//g' < filename > filename1

...but it doesn't work. Also, this being an escape character, does it add more complexity than it would take to eliminate a normal character?

Thanks in anticipation.
# 2  
Old 03-27-2006
transfer in ascii mode

This is common problem if you transfer in binary mode. Try transferring in ascii mode. You can use
tr -d '^M' <file_name
to delete.
# 3  
Old 03-27-2006
run "dos2unix" on that file and it should get resolved.
# 4  
Old 03-27-2006
If you just wan to delete all control chars without having to pipe to a new file and rename it, use:

This will get rid of all the control chars in the file.
Code:
echo '%s/[[:cntrl:]]//g\nwq' | ex filename

Or use
This will just delete the ^M's
Code:
echo '%s/\015//g\nwq' | ex filename

# 5  
Old 03-28-2006
thank you very much for your inputs.. it was of great help ... Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Shell script remove bad character

I was curious to know how to write into my shell script to remove a character. The character I want to remove is  within a .html file. (18 Replies)
Discussion started by: graphicsman
18 Replies

3. Shell Programming and Scripting

Script to search for a character in files in a Directory & remove it

Hi All, Am new to both Unix & this Forum - Need some help on a script that I am trying to write: In a Directory i have few text files which might or might not contain some text that I am trying to find. Once that text is found in any of the files, it needs to be removed from the file ... (6 Replies)
Discussion started by: rituparna_gupta
6 Replies

4. Linux

Linux script to remove a character in a file based on position.

Greetings, We have a requirement where we need to loop in a fixed width file in linux and remove a character based on a position for every record. It would highly appreciate if someone can help to automate this. Appreciate your time and help! Regards (3 Replies)
Discussion started by: mailme0205
3 Replies

5. Shell Programming and Scripting

getting garbage in the output file of shell script

Hi, I wrote one shell script and I am calling 1 sql script inside shell script. When I am running the shell script, I am getting actual data as well as garbage data in the output file. Why the garbage is there in the log file. Please help if anybody having any ides. Script: ------- ... (2 Replies)
Discussion started by: vsachan
2 Replies

6. Shell Programming and Scripting

getting garbage in the output file of shell script

Hi Everyone, The problem is that I am getting messages other than the script in the current log file. Ideally the script should contain only the messages that are redirected to the log file. How to remove these unwanted data from the log file. Please help if you have any idea how to remove the... (0 Replies)
Discussion started by: vsachan
0 Replies

7. Shell Programming and Scripting

shell script to remove the last character(.) of a string

hi I have a list of words in a text file. these words are appended by "." at their end. They look something like this. word1. word2. word3. word4. word5. I need to remove the last character "." from all the words. The output must look something like this. word1 word2 word3... (7 Replies)
Discussion started by: ss3944
7 Replies

8. Shell Programming and Scripting

Script to remove first character if it is zero

Hi All, I have a input like this. 01 i want the output like this. 1 But if the input file is like 11 i should not do anything. Can anyone please help to get a command to do this. thanks, Giri. ---------- Post updated at 02:11 AM ---------- Previous update was at 02:04 AM ----------... (5 Replies)
Discussion started by: girish.raos
5 Replies

9. Shell Programming and Scripting

Remove Garbage Output

Hello Friends, In a script i m using different temporary file and i remove them in the end. During script execution i have some garbage output which is not required. For example: Garbage Output ++ rm temp_out temp_a temp_b temp_c ++ rm Filter1 Filter2 Script : Even i am redirecting rm... (7 Replies)
Discussion started by: Danish Shakil
7 Replies
Login or Register to Ask a Question