LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Find a value following a string (https://www.linuxquestions.org/questions/linux-newbie-8/find-a-value-following-a-string-345680/)

sgracelin 07-22-2005 07:17 AM

Find a value following a string
 
I have a requirement that I need to get the value of a variable stored in a file..the content will be as follows..

proc="Agent",clause="-l 444441 -p 222221 -i 191.161.1.71 -t 60 -s 1",rstcnt="3",t="60",-s="0",critical="no",prty="20";

the position of the variables is not fixed..For example -p can come anywhere in the line..If I give -p then it should return me 222221. If I give -i 191.161.1.71 , if I give critical then it should return "no" ie for any string given it should get the next value.

Is it possible to do it in shell script???..Pls give ur inputs..

slackie1000 07-22-2005 08:41 AM

hi there,
yep, it is possible to use shell script.
what should be the output of "-s"? it appears twice....
my tip is
*disclaimer : not tested. from the top of my head..
Code:

#!/bin/sh
awk -F "$1" '{print $2}' $your_file_name_here

calling the script like..
Code:

myscript.sh $whatever..
can you figure the rest? post back if you have problems..
regards
slackie1000


All times are GMT -5. The time now is 06:38 PM.