Remove first NULL Character in Flat File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove first NULL Character in Flat File
# 1  
Old 10-06-2017
Remove first NULL Character in Flat File

We have a flat file with below data :

Code:
^@^@^@^@00000305^@^@^@^@^@^@430^@430^@^@^@^@^@^@^@^@^@09079989530

As we can see ^@ is Null character in this file
I want to remove only the first few null characters before string 00000305
How can we do that, any idea. I want a new file without first few null characters before string 00000305.

Output file format required : 00000305^@^@^@^@^@^@430^@430^@^@^@^@^@^@^@^@^@09079989530
# 2  
Old 10-06-2017
Hello simpltyansh,

Could you please try following and let me know if this helps you.
Code:
awk '{sub(/[^[:digit:]]*/,"");print}'

Output will be as follows.
Code:
00000305^@^@^@^@^@^@430^@430^@^@^@^@...@^@09079989530

Thanks,
R. Singh
# 3  
Old 10-06-2017
Quote:
Originally Posted by RavinderSingh13
Hello simpltyansh,

Could you please try following and let me know if this helps you.
Code:
awk '{sub(/[^[:digit:]]*/,"");print}'

Output will be as follows.
Code:
00000305^@^@^@^@^@^@430^@430^@^@^@^@^@^@^@^@^@09079989530

Thanks,
R. Singh
Hi Ravinder,

I used below code and it removed all the NULL characters.

Code:
cat file1 | awk '{sub(/[^[:digit:]]*/,"");print}' >> file2

Need urgent help.
# 4  
Old 10-06-2017
Quote:
Originally Posted by simpltyansh
Hi Ravinder,
I used below code and it removed all the NULL characters.
Code:
cat file1 | awk '{sub(/[^[:digit:]]*/,"");print}' >> file2

Need urgent help.
Hello simpltyansh,

Please do not use words like "Urgent", it is not encouraged to use these kind of words in forums. Could you please let me know what has NOT worked? Because as per your shown output it worked, please be clear in your questions/asks, show more sample Input_file with code tags and show sample expected output(with all conditions) in code tags too.

Thanks,
R. Singh
# 5  
Old 10-06-2017
NULL characters are always difficult to handle for *nix text tools... try, though,
Code:
sed 's/^[[:cntrl:]]*//' file

# 6  
Old 10-06-2017
By definition, UNIX text utility tools work on text files, and text fiies do not contain NUL bytes. Some text utilities on some operating systems can handle NUL bytes even though doing so is not required by the standards. But, of course, you haven't bothered to tell us what operating system you're using.

Are there always three NUL bytes that you want to remove? Or, does the number of NUL bytes vary? If the number varies, you can use something like od to determine the number of leading NUL bytes and then you can use dd to skip over those bytes and copy the rest of the data in the file to another file.
These 2 Users Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

To flat file, append null or space if its length is less than 10

Hi, We receive flat files with fixed width data Now our goal is append from right null or space to each record if the lenght of the record is less than for example 10. for example 123 45 6 0 123 45 123 45 6 123 and output should be 123 45 6 0 123 45**** 123 45 6**... (7 Replies)
Discussion started by: shharrath
7 Replies

2. UNIX for Advanced & Expert Users

Remove duplicates in flat file

Hi all, I have a issues while loading a flat file to the DB. It is taking much time. When analyzed i found out that there are duplicates entry in the flat file. There are 2 type of Duplicate entry. 1) is entire row is duplicate. ( i can use sort | uniq) to remove the duplicated entry. 2) the... (4 Replies)
Discussion started by: samjoshuab
4 Replies

3. UNIX for Dummies Questions & Answers

How to remove numeric characters in the flat file

HI, can any one help me please .. i have flat file like qwer123rt ass3242ccf jjk654 kjh838ppp nhdg453ok hdkk34 i want remove numeric characters in the flat file i want output like this qwerrt assccf jjk kjhppp nhdgok hdkk help me... (4 Replies)
Discussion started by: rafimd1985
4 Replies

4. UNIX for Advanced & Expert Users

Insertion of Null Character while writing into file

I have a huge file with record length around 5000 characters. There is an ETL tool datastage which is writing this data to the file(AIX server). At position 4095 i have seen NULL Character(^@). when i am using this command "head -1 file_nm | sed 's/\000//g'" --- the output is displaying... (3 Replies)
Discussion started by: issaq84mohd
3 Replies

5. Shell Programming and Scripting

Read from Multiple character delimited flat file

Hello Guys I have a multiple character delimited flat file "|~|". when I tried to read the data the "|" character also coming Example I/P file 9882590|~|20111207|~|K03501000063005574033961|~|K|~| Command to get the second column I used awk -F"|~|" ' {print $2}' ... (2 Replies)
Discussion started by: Pratik4891
2 Replies

6. Shell Programming and Scripting

Remove somewhat Duplicate records from a flat file

I have a flat file that contains records similar to the following two lines; 1984/11/08 7 700000 123456789 2 1984/11/08 1941/05/19 7 700000 123456789 2 The 123456789 2 represents an account number, this is how I identify the duplicate record. The ### signs represent... (4 Replies)
Discussion started by: jolney
4 Replies

7. UNIX for Dummies Questions & Answers

how to remove the first line from a flat file ?

Hi, I want to remove the first line from a flat file using unix command as simple as possible. Can anybody give me a hand ? Thanks in advance. xli (21 Replies)
Discussion started by: xli
21 Replies

8. UNIX for Dummies Questions & Answers

How to remove null characters from file?

I'm trying to remove the null characters from a file and copy it to std output. I'm using emacs and I create the following one line bash file (followed by the error messages): sed -e 's/^@//' <ConfigItemReplicator.install.log /usr/bin/bash: -c: line 0: unexpected EOF while looking for... (1 Reply)
Discussion started by: siegfried
1 Replies

9. Shell Programming and Scripting

How to remove page breaks from a flat file???

Hi All, I get a flat file with its last field data splitting onto a new line.I got this program from Vgersh which when run would cancatenate the split data back to the end of the previous records.But this program fails when it encounters a page break between the split data and the previous... (5 Replies)
Discussion started by: kumarsaravana_s
5 Replies

10. Shell Programming and Scripting

Sorting a flat file based on multiple colums(using character position)

Hi, I have an urgent task here. I am required to sort a flat file based on multiple columns which are based on the character position in that line. I am restricted to use the character position instead of the space and sort +1 +2 etc to do the sorting. I understand that there is a previous... (8 Replies)
Discussion started by: cucubird
8 Replies
Login or Register to Ask a Question