Linux bash将输出存储为变量
将返回从大型文本文件中提取的列表中最大的一个,但如何将输出存储为变量?使用: 另外,为了便于携带,我建议始终使用Linux bash将输出存储为变量,linux,bash,Linux,Bash,将返回从大型文本文件中提取的列表中最大的一个,但如何将输出存储为变量?使用: 另外,为了便于携带,我建议始终使用-n1作为头的参数。我曾经遇到过一些使用-1不起作用的实例。我建议 my_var=$(grep -A 26 "some text" somefile.txt | awk '/other text/ { gsub(/M/, " "); print $4 }' | sort -n -r | uniq | head -n1) 对于未列出的情况,反引号也适用: variable_
-n1
作为头的参数。我曾经遇到过一些使用-1
不起作用的实例。我建议
my_var=$(grep -A 26 "some text" somefile.txt |
awk '/other text/ { gsub(/M/, " "); print $4 }' |
sort -n -r | uniq | head -n1)
对于未列出的情况,反引号也适用:
variable_name=$(grep -A 26 "some text" somefile.txt |
awk '/other text/ { gsub(/M/, " "); print $4 }' |
sort -nru | head -1)
variable_name=$(grep -A 26 "some text" somefile.txt |
awk '/other text/ { gsub(/M/, " "); print $4 }' |
sort -nru | head -1)
variable=`grep -A 26 "some text" somefile.txt |
awk '/other text/ { gsub(/M/, " "); print $4 }' |
sort -nru | head -1`