Get rid of junk character in a file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Get rid of junk character in a file
# 1  
Old 08-14-2007
Get rid of junk character in a file

I have a file with one of the following lines, when opened with vi
33560010686GPT£120600GBPGBP10082007DS
In the above line, I want to get rid of the junk character before the £ (pound sysmbol).
When I tried copying £ from windows and copy in unix vi, it prints as £ and I tried pattern replace options in vi, but of no use

Thanks in advance
# 2  
Old 08-14-2007
Assume you have a file named "file.txt", containing only one of your "dirty" line. First, you have to determine the octal code of the junk character, which is the 15th of the line:

Code:
od -b file.txt

0000000 063 063 065 066 060 060 061 060 066 070 066 107 120 124 302 243
0000020 061 062 060 066 060 060 107 102 120 107 102 120 061 060 060 070
0000040 062 060 060 067 104 123 012
0000047

Now that you have the octal representation of the character you want to remove, try:

Code:
cat file.txt | tr -d '\302'

Bye Smilie
# 3  
Old 08-14-2007
Thanks a lot robotronic.
That really works
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

Help in viewing the junk character

Hello All, I have issues in unix file when I loaded that to database and do select * from table where description like '%'+char(13)+'%' on it I am able to get records. I tried to view the file in unix it is all having blank character which I think is all non ascii which I am not able view.... (11 Replies)
Discussion started by: arunkumar_mca
11 Replies

2. Shell Programming and Scripting

Junk character appearing after downloading the file from windows server

Hello, Im downloading the file from windows server through FTP, the downloaded file is containing some junk character at very start of the file as below and causing my whole script is to fail, how to download without junk or how to remove these before processing it? ▒▒"nmdbfnmdsfsdf" ... (19 Replies)
Discussion started by: Riverstone
19 Replies

3. Shell Programming and Scripting

How to see junk character in file in.?

Hi I want to know how to see junk character in a file. i am not able to see junk character using vi or cat command. below is the junk char . which i see in host file 10.178.14.67▒▒▒ ac01sp02-vip actually it should be like this 10.178.14.67 ac01sp02-vip i am using secure CRT... (11 Replies)
Discussion started by: scriptor
11 Replies

4. Shell Programming and Scripting

removing of junk character

Dear ALL, How to remove junk charecter ^M from unix file i am using sun solaris unix. I already tried few commands :%s/^M//g :%s/r//g but it didnt helped me. Any help appriciated. Thanks Ripudaman Please view this code tag video for how to use code tags when posting code... (5 Replies)
Discussion started by: ripudaman.singh
5 Replies

5. Shell Programming and Scripting

Check Junk character in sql file

Hello, I have two .sql files which I transferred from Windows to Unix (Linux Enterprise Linux Server release 5.3).I want to ensure that these two files have no junk characters in them.How do I do it in the simplest possible way? Many thanks DJ (1 Reply)
Discussion started by: Digjoy83
1 Replies

6. Shell Programming and Scripting

get rid of "^" character in a .txt file

I have a file that I ran the dos2unix utility on, it cleans up pretty well, but I noticed an occasional ^M leftover, (actual characters) these may or may not be strays from my original dos file. Either way, I want to get rid of the ^ and any character that may follow. ^M ^C or whatever. How do I... (6 Replies)
Discussion started by: ajp7701
6 Replies

7. Shell Programming and Scripting

Remove all JUNK character from file.

Hi Team, I have a file having size greater than 1 GB. What i want to do is to check if it contains any JUNK character (ie any special charater thats not on the key board stroke). This file has 532 column & seperated with ^~^. I have found some solution from the file, but it is for a... (4 Replies)
Discussion started by: Amit.Sagpariya
4 Replies

8. Shell Programming and Scripting

How can I get rid of the ` character from input file?

A sed command works most of the time however it fails sometimes. I put each line (record) I read of a file through the following command data=$(cat file | sed 's///g' | sed 's|.*ex:Msg\(.*\)ex:Msg.*|\1|' ) When I run the script I get a message that states that there is an invalid format... (6 Replies)
Discussion started by: gugs
6 Replies

9. Shell Programming and Scripting

Junk Character in file

Hi set filename "./GopiRun.sh" if } err] { writeLog "error in exec " writeLog $a } else { writeLog $a } The above code will execute a file GopiRun.sh,and will log the output of the exec to a file. The problem is the file has lot of junk character in it,how to avoid it. The... (2 Replies)
Discussion started by: nathgopi214
2 Replies

10. UNIX for Dummies Questions & Answers

How to remove junk (^Ò) character while FTPing

Hi All, I have been trying to FTP some data files from Windows directory to a UNIX server. The txt file in the windows contails the following data: "111~XYZ~1~Contact person’s phone number~COMMENTS~~~~" but the same line is appearing as "111~XYZ~1~Contact person^Òs phone number~COMMENTS~~~~"... (8 Replies)
Discussion started by: vkumbhakarna
8 Replies
Login or Register to Ask a Question