Removing Null data in output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing Null data in output
# 1  
Old 08-13-2007
Removing Null data in output

Hello all,

I have a script that has an infile with system package information. For the most part the script is looking well. The only thing i need help is in testing for null entries and removing null data.


#!/usr/bin/ksh

for i in `cat /mwncps/bin/eco_pack`

do

NAME=`pkginfo -l | grep $i | grep 'NAME' | awk '{ print $5 }'`
VER=`pkginfo | grep $i | grep version | awk 'BEGIN {OFS=" "}{gsub(/version:/,"") ;}{ print $7 }'`

echo "`hostname`,"$NAME","$VER""

done

The output now looks like this

hostname,,
hostname,,
hostname,package,version <-- this part of the output is correct
hostname,package,version
hostname,package,version
hostname,package,version
hostname,, <-- this will need to be removed completely
hostname,,

I welcome your feedback

Regards,

Al
# 2  
Old 08-13-2007
try something like this
Code:
#!/usr/bin/ksh

while read i
do

  	NAME=`pkginfo -l | grep $i | grep 'NAME' | awk '{ print $5 }'`
  	VER=`pkginfo | grep $i | grep version | awk 'BEGIN {OFS=" "}{gsub(/version:/,"") ;}{ print $7 }'`
	if [[ -z $NAME ]]; then
   		continue
   	fi	
	echo "`hostname`,"$NAME","$VER""

done < /mwncps/bin/eco_pack > outputfile

# 3  
Old 08-13-2007
I just incorporated this portion

if [[ -z $NAME ]]; then
continue
fi
and that did the trick.

Many thanks,

AlSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Parsing null or empty output

I am working an some if then statements for a script. I want to be able to check for alpha characters or empty out put then exit out. if ]]; echo "Serial Number Invaild" then exit 3; How do I account if the output is empty or null in this in this statement. Many thanks (6 Replies)
Discussion started by: andysensible
6 Replies

2. Shell Programming and Scripting

How to handle NULL value output from ISQL command?

I am using ISQL command in ksh script. Suppose if i get NULL value from the query which i run,how can i handle it? I am getting a NULL result set and the following error is coming. ############### output of isql command for getting the sum of JEs ################ ----------- NULL... (4 Replies)
Discussion started by: Sharma331
4 Replies

3. Shell Programming and Scripting

redirect the audio output to /dev/null

I'm using an text-to-speech synthesis in a script, and I need to redirect it's output to /dev/null how can I do that ? And how to redirect the stream to his normal output then (sound card ) ? thankx (2 Replies)
Discussion started by: firelink
2 Replies

4. Shell Programming and Scripting

How to replace null data using SED

Hi, I have following data in a file 5~6.14~S~N~N~0.~4565~134~6584  ~6.13~H~N~N~0.~4578~0~6587 2~6.14~S~N~N~0.~4565~134~6584  ~3.13~H~N~N~0.~4578~0~6587 -~6.14~S~N~N~0.~4565~134~6584  ~7.13~H~N~N~0.~4578~0~6587 I want the output as 5~6.14~S~N~N~0.~4565~134~6584... (2 Replies)
Discussion started by: sol_nov
2 Replies

5. Shell Programming and Scripting

Redirect system output to null in perl

Hi Guys, Please help me.. it is urgent. I am writing a perl script to capture command output and redirect it to a logfile.At the same i want to check the return code of the command and log it if the command is not succesful in my logfile.. Here is my code, it is working but system command inside... (2 Replies)
Discussion started by: sriramperumalla
2 Replies

6. Shell Programming and Scripting

Error output of cat to /dev/null

Hello, I'm trying to send the error output of a 'cat' operation to /dev/null like this: cat /dirA/dirB/temp*.log > /dirA/dirB/final.log 2>/dev/null This works perfectly in a terminal, but not when placed in a script. If there are no files matching temp*.log the script outputs an error... (7 Replies)
Discussion started by: Nils88
7 Replies

7. Shell Programming and Scripting

SFTP to server, pulling data and removing the data

Hi all, I have the following script, but are not too sure about the syntax to complete the script. In essence, the script must connect to a SFTP server at a client site with username and password located in a file on my server. Then change to the appropriate directory. Pull the data to the... (1 Reply)
Discussion started by: codenjanod
1 Replies

8. UNIX for Dummies Questions & Answers

data is seen as NULL after loading into database

hello, when I load a data from text file all the values become NULL in the table. Please help me with this problem. Thanks sheen (15 Replies)
Discussion started by: sheen
15 Replies

9. UNIX for Dummies Questions & Answers

cp output /dev/null results in not a directory

Hello, I am working on a script to measure the read performance of a busybox environment. The logical choice is to use a command line like: (time cp * /dev/null) 2> /tmp/howlong.txt Ah, the rub is cp or /dev/null will only accept a single file at a time. The result in the txt file is and... (1 Reply)
Discussion started by: stevesmo
1 Replies

10. Shell Programming and Scripting

finding null records in data file

I am having a "|" delimited flat file and I have to pick up all the records with the 2nd field having null value. Please suggest. (3 Replies)
Discussion started by: dsravan
3 Replies
Login or Register to Ask a Question