Computer Hope
Software => BSD, Linux, and Unix => Topic started by: viceroy2528 on July 15, 2010, 11:20:55 AM
-
Would anyone by chance have a Unix Script that would parse the output of a command for the required data and then issue another command with this data?
-
Take a look at
Unix Script Examples
http://UNIX.ittoolbox.com
-
Would anyone by chance have a Unix Script that would parse the output of a command for the required data and then issue another command with this data?
what are you trying to parse? describe more clearly what you want to do.
-
Command
tesmcmd jobmon +i -a 41844
Return
<execute>
<cmd_name>jobmon</cmd_name>
<result>
<jobrun>
<job_run_id>3318780</job_run_id>
</jobrun>
</result>
I want to take the returned job_run_id and pass it to command
tesmcmd jobrelease 3318780
-
linux$ var=$(tesmcmd jobmon +i -a 41844 | awk -vRS="</job_run_id>" '/job_run_id/{gsub(/.*job_run_id>/,"");print}')
linux$ tesmcmd jobrelease $var
-
Alternately,
var="$(tesmcmd jobmon +i -a 41844 | sed -n "/run_id/s/[^0-9]//gp")"
tesmcmd jobrelease $var
Some explanation:
var="$( ... )" captures the output to a variable,
-n tells sed to not output anything unless the p flag is given,
/run_id/ selects only the line that has that text,
s/...// is the substitution syntax, though we are substituting nothing thus deleting,
[^0-9] matches any non-numeric character,
g makes the substitution global on matching lines,
p means print the results.