Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

How to remove the ^@ character in a file.

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-03-2012
machomaddy machomaddy is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 18 December 2014, 1:05 PM EST
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.

ThanksUnix or Linux Image
Sponsored Links
    #2  
Old Unix and Linux 01-03-2012
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Last Activity: 14 April 2015, 8:02 PM EDT
Posts: 6,398
Thanks: 288
Thanked 675 Times in 644 Posts
Can delete nulls with "tr".


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

Sponsored Links
    #3  
Old Unix and Linux 01-03-2012
sdebasis's Unix or Linux Image
sdebasis sdebasis is offline
Registered User
 
Join Date: Nov 2011
Last Activity: 6 April 2015, 6:42 AM EDT
Posts: 23
Thanks: 10
Thanked 2 Times in 2 Posts
Hi
Try this

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

Unix or Linux Image

Last edited by sdebasis; 01-03-2012 at 09:47 AM..
    #4  
Old Unix and Linux 01-03-2012
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Last Activity: 14 April 2015, 8:02 PM EDT
Posts: 6,398
Thanks: 288
Thanked 675 Times in 644 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 Unix and Linux 01-03-2012
machomaddy machomaddy is offline
Registered User
 
Join Date: Dec 2011
Last Activity: 18 December 2014, 1:05 PM EST
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.

Unix or Linux Image
Sponsored Links
    #6  
Old Unix and Linux 01-03-2012
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Last Activity: 14 April 2015, 8:02 PM EDT
Posts: 6,398
Thanks: 288
Thanked 675 Times in 644 Posts
Must have been nulls.
Sponsored Links
    #7  
Old Unix and Linux 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 09:46 PM.