【发布时间】:2018-04-12 11:30:31
【问题描述】:
我在 shell 脚本中有一个变量,如下所示。每行由换行符分隔。
var="This is the first line
This is the second line
This is the third line
/home/usr/new/foo.txt
This is the forth line
This is the fifth line"
现在我需要读取其中包含.txt 的行并将其存储在另一个变量中。
another_var=/home/usr/new/foo.txt
【问题讨论】:
-
像魅力一样工作,谢谢:)
-
感谢您发现它很有用。您还可以通过您尝试过的相关努力来更新问题,以便将来有所帮助吗?
-
我认为
grep可以选择行...如var2="$(echo "$var" | grep '.txt$')"