bash检查列表中的所有元素是否在一个范围内 LessThanThirty=1 大于二十=1 读行时 做 LessThanThirty=$(回音“$line=20.0”|公元前) 完成
只需在bash检查列表中的所有元素是否在一个范围内 LessThanThirty=1 大于二十=1 读行时 做 LessThanThirty=$(回音“$line=20.0”|公元前) 完成,bash,Bash,只需在awk中进行比较: LessThanThirty=1 GreaterThanTwenty=1 while read line do LessThanThirty=$(echo "$line <= 30.0" | bc) GreaterThanTwenty=$(echo "$line >= 20.0" | bc) done < <(grep -A 26 "some text" someFile.txt | awk '/More Text/ { gs
awk
中进行比较:
LessThanThirty=1
GreaterThanTwenty=1
while read line
do
LessThanThirty=$(echo "$line <= 30.0" | bc)
GreaterThanTwenty=$(echo "$line >= 20.0" | bc)
done < <(grep -A 26 "some text" someFile.txt | awk '/More Text/ { gsub(/M/, " "); print $4 }' | uniq )
echo $LessThanThirty
echo $GreaterThanTwenty
读得大于二十小于三十<我想你可以只是或者把你的变量放在一起:
read GreaterThanTwenty LessThanThirty < <(
grep -A 26 "some text" someFile.txt | \
awk '/More Text/ { gsub(/M/, " "); print $4 }' | \
awk 'BEGIN { g20=l30=1 }
$0 < 20.0 { g20=0 }
$0 > 30.0 { l30=0 }
END { print g20, l30 }'
)
LessThanThirty=0
大于二十=0
读行时
做
LessThanThirty=$(回音“$线=20.0 | |$大于二十”|公元前)
对不起,这有点含糊不清。为清晰起见,编辑了问题。你能一步一步地解释一下吗?我对bash还不是很熟悉,昨天才发现了awk;我会加上一个解释。很确定这正是我需要的!现在我需要清理我发送的输入。事实上,每一行都有“更多的文本”被解析,但我真正需要的是只检查文件中某一点的文本…答案中的代码按预期工作,但是你能解释一下这里发生了什么吗?如果[[$GreaterThanTwenty==1&&$LessThanThirty==1]]会触发内限,即使进一步的回声显示此时LessThanTwenty实际上为0。然后回显“限内”或回显“限外”fi
LessThanThirty=0
GreaterThanTwenty=0
while read line
do
LessThanThirty=$(echo "$line <= 30.0 || $LessThanThirty" | bc)
GreaterThanTwenty=$(echo "$line >= 20.0 || $GreaterThanTwenty" | bc)
done < <(grep -A 26 "some text" someFile.txt | awk '/More Text/ { gsub(/M/, " "); print $4 }' | uniq )
echo $LessThanThirty
echo $GreaterThanTwenty