How to search word of the output of a shell script and save in other variable .
Below command will display the list of baselines in my view .
cmd :cleartool lsstream -fmt "%[found_bls]NXp\n" -view $VIEW_NAME
Output :
baseline:MHC_BUILDTREE1.0.1
baseline:JEPG_DUIF_CI
baseline:MOR_BuildTree_BLD_I.0.1
I need to search the line which contains "MOR_BuildTree"
and that output line i have to save in one variable to execute the rest of the commands .
Can any one give the suggestion ?
Isn't this a simple piece shell scripting?
The
-n
options means 'do not print by default'. The command looks for your name, removes the leadingbaseline:
and prints it.Not exactly sure what you are asking, but to set a variable to the result of a command, you can use:
or you can pipe your command to some filter to reformat it as required.
you can also combine the two:
Here is what I just tested to get one baseline out of all the foundation baselines:
(set
$yourBaselineName
to the appropriate name you want to extract)The main difficulty comes from the fact an
lsstream -fmt "%[found_bls]CXp"
will list all foundation baselines on the same output line (so the output is only one line of baseline names, separated by comma).You need to split the line into multiple ones first.
See "How to split one string into multiple strings in bash shell?": that is the
tr -s " " "\\012"
part of the above command.Then you need to remove what precede and follow the baseline name:
The
sed
part of the above command can do that:(two regular expressions remove everything before the '
:
' and after the '@
')