How can we do this?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can we do this?
# 8  
Old 08-29-2008
Sorry, your code doesn't make much sense. Can you describe exactly what you are trying to do here? Are you trying to search for the string "grep $1", or are you trying to run grep against abc.sh and using the first parameter as the search string?

You can't use other shell script commands inside an awk script.

Also you wouldn't normally provide input to awk both via a pipeline (i.e. stdin) and by providing an input file name... use one or the other (unless you know exactly what you're doing).
# 9  
Old 08-29-2008
Hi,

cat abc.sh| grep $1 | grep Failure | awk '/$1/ && /Failure/{getline;print;exit}' /root/shell/abc.sh

is the code actually i had written

What actually I want to do is I want to print the line which is next to the line in which both the strings, One which I gave as the command line argument($1) and the second 'Failure' are there in the file abc.sh


Can you suggest me a better code.

Thanks,
Prakash.
# 10  
Old 08-29-2008
Well, with your code the awk part will never be able to print the line after the Failure because the previous greps will have already filtered it out.

Try:

Code:
awk -v searchstring="$1" '$0 ~ searchstring && /Failure/ { getline; print }' /root/shell/abc.sh

# 11  
Old 08-29-2008
By the way, it seems strange to me that you are searching for the string 'Failure' in a shell script. I'm presuming abc.sh is a script? Are you sure you don't want to search for it in the output of abc.sh, rather than the script itself?
# 12  
Old 08-29-2008
Hi,
Thanks for your help.
I have got the output which i require.
thanks a lot.

Can you please say me why you have written so ?
What is the function of -v and all here?

Prakash.

Last edited by prakashreddy; 08-29-2008 at 03:38 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question