我正在尝试根据第 5 列值打印日志文件的行,但最后出现错误。
脚本.sh
num=0
str=" "
tail -n 10000 /var/temp.log | awk '$5=="[200]" {print}'
echo -n "Enter the first number --> "
read num
str="'\$5==\"[$num]\" {print}'"
echo This is the string for awk argument
echo $str
echo
tail -n 10000 /var/temp.log | awk $str
//getting error here
运行 script.sh ==> ./script.sh 后
Prints the lines which are consisting [200] in the column 5 of log file.
Enter the first number --> 100
This is the string for awk argument
'$5=="[100]" {print}'
awk: '$5=="[100]"
awk: ^ invalid char ''' in expression
我该如何解决 ?
提前致谢。