How to remove the ^@ character in a file. | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

How to remove the ^@ character in a file.

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-03-2012
machomaddy machomaddy is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 19 August 2014, 9:18 AM EDT
Posts: 81
Thanks: 33
Thanked 2 Times in 2 Posts
How to remove the ^@ character in a file.

I receive a file which is Dos format. When I view the file using vi, I was able to find ^M, ^@ characters in beteen records. I wanted to remove these control/special characters. I used the
Code:
dos2unix

command. This removed the ^M characters. But I am unable to remove the ^@ character. I tried even the
Code:
sed 's/^@//g'

but no use. Please help me on removing the ^@ character.


Code:
Sample File
=========
1|insured^@to bcb^@sm.


Code:
Expected Output
=========
1|insuredtobcbsm.

Thanks
Sponsored Links
    #2  
Old 01-03-2012
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Last Activity: 18 April 2014, 5:13 AM EDT
Posts: 6,396
Thanks: 287
Thanked 673 Times in 642 Posts
Can delete nulls with "tr".


Code:
cat oldfile | tr -d "\000" > newfile

Sponsored Links
    #3  
Old 01-03-2012
sdebasis's Avatar
sdebasis sdebasis is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 1 October 2014, 6:38 AM EDT
Posts: 23
Thanks: 9
Thanked 2 Times in 2 Posts
Hi
Try this

Code:
sed 's/\^@/ /g' < filename |tr -d " "


Last edited by sdebasis; 01-03-2012 at 09:47 AM..
    #4  
Old 01-03-2012
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Last Activity: 18 April 2014, 5:13 AM EDT
Posts: 6,396
Thanks: 287
Thanked 673 Times in 642 Posts
I've assumed that you were viewing the file with "cat -v" and seeing each null character as ^@ . sdebasis is assuming two ascii characters ^ and @ .
Please clarify what is in the file:

Code:
od -oc filename

Nulls should show as \0 by this method.
The Following User Says Thank You to methyl For This Useful Post:
machomaddy (01-03-2012)
Sponsored Links
    #5  
Old 01-03-2012
machomaddy machomaddy is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 19 August 2014, 9:18 AM EDT
Posts: 81
Thanks: 33
Thanked 2 Times in 2 Posts
@Methyl

I was using VI editor to view this file.

Your code

Code:
 cat oldfile | tr -d "\000" > newfile

works!! the ^@ characters were removed.

Sponsored Links
    #6  
Old 01-03-2012
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Last Activity: 18 April 2014, 5:13 AM EDT
Posts: 6,396
Thanks: 287
Thanked 673 Times in 642 Posts
Must have been nulls.
Sponsored Links
    #7  
Old 01-03-2012
tarun_agrawal tarun_agrawal is offline
Registered User
 
Join Date: Jul 2011
Last Activity: 29 May 2012, 10:09 PM EDT
Posts: 87
Thanks: 0
Thanked 16 Times in 15 Posts
Try this

Code:
sed 's/[[:cntrl:]]//g' filename


Last edited by Franklin52; 01-04-2012 at 02:39 AM.. Reason: Please use code tags for code and data samples, thank you
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to remove first 2 character from file name atul9806 Shell Programming and Scripting 8 06-14-2011 08:21 AM
Remove special character ($) from file names competitions Shell Programming and Scripting 6 06-03-2011 08:56 AM
How to remove new line character and append new line character in a file? sasikari HP-UX 8 10-27-2010 06:09 PM
remove backslash character from file MissI Shell Programming and Scripting 2 08-12-2009 02:06 PM
Remove all JUNK character from file. Amit.Sagpariya Shell Programming and Scripting 4 01-30-2009 09:55 AM



All times are GMT -4. The time now is 07:49 AM.