Null Characters


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Null Characters
# 1  
Old 08-29-2005
Null Characters

How do I get rid of null characters/strings in a unix text file. I need to use this in a script. When I use dev/null it puts null characters in my file and makes it larger. Please help
# 2  
Old 08-29-2005
What exactly do you mean, what are you using /dev/null for?

When I use it as a null device that exactly how it behaves:

Code:
user1@balrog ~
$ touch emptyfile

user1@balrog ~
$ ls -l emptyfile 
-rw-r--r--  1 user1 staff 0 Aug 30 01:15 emptyfile

user1@balrog ~
$ cp /dev/null emptyfile 

user1@balrog ~
$ ls -l emptyfile 
-rw-r--r--  1 user1 staff 0 Aug 30 01:15 emptyfile

user1@balrog ~
$ cat /dev/null > emptyfile 

user1@balrog ~
$ ls -l emptyfile 
-rw-r--r--  1 user1 staff 0 Aug 30 01:15 emptyfile

# 3  
Old 08-30-2005
To remove nulls from a file...
Code:
sed 's/\x0//g' file1 > file2

# 4  
Old 01-13-2006
Question Replace Binary Nulls with spaces using Unix cmd

Hi,

We have an input datafile coming in from a different source. When this file is being processed by the Unix code on a AIX machine, it give a different record count and fails reconciliation with the expected couts. In short the Binary Nulls are getting treated differently when we are doing a processing of file. The main thing change is when we redirect the data from the input data file to another temporary file to remove the last line, which is a control record.

In this process the file that gets created as a totally different record length as the binary nulls are being treated differently by the unix.

Please advice.
# 5  
Old 01-13-2006
MVS ignores nulls, UNIX does not - for example. You will have to change the "binary nulls" to spaces
Code:
sed 's/\x0/ /g' file1 > file2

# 6  
Old 01-13-2006
But this means that we are modifying inpur data, which is really not possible. If a binary null has come in a number field position then it will throw an error at oracle level.
But if we replace the binary Nulls with space then it will throw an error for invalid data.
And also if binary nulls is in a varchar field which is a unique constraint then space will be taken as a value and the wrong data will be entered.

I dont think replacing them with the space is not a good idea.

I saw another thread talkingabout the following command

perl -pi -e '$_ = "" if ($. == 1);' filename

All I need is to remove the last line of control record from the input file and go ahead.

Please let me know if this approach is right. Do you foresee any negative consequence?

Thx
Arch
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Outputting characters after a given string and reporting the characters in the row below --sed

I have this fastq file: @M04961:22:000000000-B5VGJ:1:1101:9280:7106 1:N:0:86 GGGGGGGGGGGGCATGAAAACATACAAACCGTCTTTCCAGAAATTGTTCCAAGTATCGGCAACAGCTTTATCAATACCATGAAAAATATCAACCACACCA +test-1 GGGGGGGGGGGGGGGGGCCGGGGGFF,EDFFGEDFG,@DGGCGGEGGG7DCGGGF68CGFFFGGGG@CGDGFFDFEFEFF:30CGAFFDFEFF8CAF;;8... (10 Replies)
Discussion started by: Xterra
10 Replies

2. Shell Programming and Scripting

Remove first 2 characters and last two characters of each line

here's what im trying to do. i have a file containing lines similar to this: data.txt: 1hsRmRsbHRiSFZNTTA1dlEyMWFkbU5wUW5CSlIyeDFTVU5SYjJOSFRuWmpia0ZuWXpKV2FHTnRU 1lKUnpWMldrZFZaMG95V25oYQpSelEyWTBka2QyRklhSHBrUjA1b1kwUkJkd3BOVXpWM1lVaG5k... (5 Replies)
Discussion started by: SkySmart
5 Replies

3. Shell Programming and Scripting

Redirecting standard out to /dev/null goes to file "/dev/null" instead

I apologize if this question has been answered else where or is too elementary. I ran across a KSH script (long unimportant story) that does this: if ; then CAS_SRC_LOG="/var/log/cas_src.log 2>&1" else CAS_SRC_LOG="/dev/null 2>&1" fithen does this: /usr/bin/echo "heartbeat:... (5 Replies)
Discussion started by: jbmorrisonjr
5 Replies

4. Shell Programming and Scripting

sed replacing specific characters and control characters by escaping

sed -e "s// /g" old.txt > new.txt While I do know some control characters need to be escaped, can normal characters also be escaped and still work the same way? Basically I do not know all control characters that have a special meaning, for example, ?, ., % have a meaning and have to be escaped... (11 Replies)
Discussion started by: ijustneeda
11 Replies

5. Shell Programming and Scripting

Replace special characters with Escape characters?

i need to replace the any special characters with escape characters like below. test!=123-> test\!\=123 !@#$%^&*()-= to be replaced by \!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Discussion started by: laknar
8 Replies

6. UNIX for Dummies Questions & Answers

/dev/null 2>&1 Versus /dev/null 2>1

How are these two different? They both prevent output and error from being displayed. I don't see the use of the "&" echo "hello" > /dev/null 2>&1 echo "hello" > /dev/null 2>1 (3 Replies)
Discussion started by: glev2005
3 Replies

7. Shell Programming and Scripting

How to replace characters with random characters

I've got a file (numbers.txt) filled with numbers and I want to replace each one of those numbers with a new random number between 0 and 9. This is my script so far: #!/bin/bash rand=$(($RANDOM % 9)) sed -i s//$rand/g numbers.txtThe problem that I have is that it replaces each number with just... (2 Replies)
Discussion started by: hellocatfood
2 Replies

8. Shell Programming and Scripting

Insert string 'NULL' where there is a null value

I have an input file having 7 fields delimited by , eg : 1,ABC,hg,1,2,34,3 2,hj,YU,2,3,4, 3,JU,kl,4,5,7, 4,JK,KJ,3,56,4,5 The seventh field here in some lines is empty, whereas the other lines there is a value. How do I insert string NULL at this location (7th loc) for these lines where... (8 Replies)
Discussion started by: zilch
8 Replies

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

10. Shell Programming and Scripting

compare null with non-null

I've got a very peculiar situation. I'm trying to find out if we can compare null fields with non-null. I've output csv files from SQL and Oracle. I need to compare each field from the files, and then find out any differences. The files usualy have over 500 fields, and send the resule to DBA.... (8 Replies)
Discussion started by: nitin
8 Replies
Login or Register to Ask a Question