Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check whether command returned any output?

Status
Not open for further replies.
Mar 31, 2004
151
US
Code:
 write header to file   
 connect sqlplus spool to sqltemp
 cat $sqltemp |  awk '{print $1, $2, $3}' | while read x y z
 do
 if something then 
    write output to file
 fi
 done

Here I would like to print header before output in a file. It should be written only if there is sqlplus output. it can't be put in loop because it repeats. Is there a way to know if cat found data in sqltemp file?
 
Something like this (in ksh)?
connect sqlplus spool to sqltemp
if [ $(awk 'NF{++nr}END{print nr}' $sqltemp) -gt 0 ]
then
write header
while read x y z remainder
do
if something then
write output
fi
done <$sqltemp
fi >/path/to/file

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top