庆典店输出作为一个变量 [英] bash store output as a variable
本文介绍了庆典店输出作为一个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
grep -A 26 "some text" somefile.txt |
awk '/other text/ { gsub(/M/, " "); print $4 }' |
sort -n -r | uniq | head -1
将返回最大的,从一个大的文本文件拉列表,但我怎么存储输出作为一个变量?
will return the largest in a list pulled from a large text file, but how do I store the output as a variable?
推荐答案
使用命令替换
my_var=$(grep -A 26 "some text" somefile.txt |
awk '/other text/ { gsub(/M/, " "); print $4 }' |
sort -n -r | uniq | head -n1)
此外,对于便携性,我会使用 -n1
为头
的说法表明总是如此。 1
我遇到一对夫妇它的化身,其中使用不工作。
Also, for portability, I would suggest always using -n1
for the argument of head
. I've come across a couple of incarnations of it where using -1
doesn't work.
这篇关于庆典店输出作为一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文