-   AIX (
-   -   AIX Shell script (

rajachan 01-16-2013 09:20 PM

AIX Shell script

i am doing aix shell scripting for first time.. i am having output file in below foramt.

sql>select data, id, profile from value and someline like this for the querey and the query ends up with semicolon;

data id profile
raj 1 system
binu 2 user
ram 3 system

can you please help me to validate the above output file and check if data=binu and id-2 and profile=user then "success"

cliffordw 01-17-2013 05:45 AM

Hi there,

Try this:


grep -q "binu 2 user" outputfile
if [ $? -eq 0 ]
  echo "success"



David the H. 01-18-2013 08:06 AM

"AIX" is an operating system, not a scripting language. What shell are you using?

(Or at least what do you have available for use? Since this is a Linux forum, the posters here are most familiar with bash.)

And please explain your exact requirements more clearly. Your sql query example has three lines of output. Do you need to search that output for an exact user match, as it seems? Or does the output need to match exactly, or what? And what should happen if any of the required strings don't match?

@cliffordw, you can simplify your test like this:


if grep -q "binu 2 user" outputfile ; then
  echo "success"

Note that this is bourne-style shell syntax (posix-supporting shells like bash or ksh). If the shell is csh-based it would probably be very different.

Also, we can't assume that the AIX version of grep has the same options as the gnu tools. "-q" might not be available. An output redirection may be necessary instead.

Edit: Ok, aix grep does have it, so at least that's not a problem.

PS: please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.

All times are GMT -5. The time now is 06:52 AM.