Home » Infrastructure » Unix » shell script
shell script [message #355175] Thu, 23 October 2008 00:35 Go to next message
lakshmi surya ram
Messages: 188
Registered: June 2006
Location: HYDERABAD
Senior Member

Hi Folks,

The following isnt working and throwing the error as
command not foundest.sh :line 6
cut:invalid byte,character or field list


#!/bin/sh
export p_resp_name=`echo " set linesize 1000
select trim(resp_appli_short_name)||','||trim(resp_name)||','||trim(Submitted_by)||','||trim(wait)||','||trim(Application_short_name)||','|| trim(conc_program_name)
from xxhl_sma_job_Schedular
where sma_job like 'SuKuRuMa';" | sqlplus -S apps/appsg3d| grep -v TRIM\* |grep -v "-"| grep -v "rows"`

echo -n "resp_appli_short_name:"
echo ${p_resp_name} | cut -d "," -f1
exit 0

Please guide...

Thanks,
Surya
Re: shell script [message #355524 is a reply to message #355175] Fri, 24 October 2008 11:32 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
your script is really difficult to read - I'd make it more modular. Plenty of examples in this forum.

To debug the immediate issue, simply echo ${p_resp_name} to see what you're piping to cut.
Re: shell script [message #355528 is a reply to message #355524] Fri, 24 October 2008 12:14 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
Use arrays or simple temp file to handle resultsets. In both examples, comma is seperator.
my_host>>cat aaa.sh
#!/bin/sh
sqlplus -s usr/pass@db <<EOF > /tmp/tmp.txt
set pagesize 0 feedback off verify off heading off echo off
select 'some space'||','||owner||','||count(*) from all_objects group by owner;
EOF

echo "method1"
#change field separator used by "read" to comma
IFS=,
while read x y z the_rest
do
  echo "x=$x y=$y z=$z"
done < /tmp/tmp.txt

echo "method2"
awk -F, '{print "x="$1, "y="$2, "z="$3}' /tmp/tmp.txt

my_host>>aaa.sh
method1
x=some space y=PUBLIC z=2455
x=some space y=SYSTEM z=13
x=some space y=SYS z=3530
x=some space y=WMSYS z=104
x=some space y=OUTLN z=3
method2
x=some space y=PUBLIC z=2455
x=some space y=SYSTEM z=13
x=some space y=SYS z=3530
x=some space y=WMSYS z=104
x=some space y=OUTLN z=3
Previous Topic: delete last character from every line in a text file
Next Topic: shell scripts to read data from a text file and to load it into a table
Goto Forum:
  


Current Time: Mon Dec 02 16:23:45 CST 2024