搜索输出行并保存在变量中 [英] search the output line and save in variable

查看:75
本文介绍了搜索输出行并保存在变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何搜索shell脚本输出的单词并将其保存在其他变量中。

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

输出:

baseline:MHC_BUILDTREE1.0.1
baseline:JEPG_DUIF_CI
baseline:MOR_BuildTree_BLD_I.0.1

我需要搜索包含 MOR_BuildTree 的行,输出行我必须保存在一个变量中才能执行其余命令。
有人可以提出建议吗?

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 ?

推荐答案

这不是简单的shell脚本吗?

Isn't this a simple piece shell scripting?

variable=$(cmd :cleartool lsstream -fmt "%[found_bls]NXp\n" -view $VIEW_NAME |
           sed -n '/MOR_Buildtree/s/^baseline://p')

-n 选项表示默认情况下不打印。该命令查找您的姓名,删除开头的基线:并打印出来。

The -n options means 'do not print by default'. The command looks for your name, removes the leading baseline: and prints it.

这篇关于搜索输出行并保存在变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆