我如何使用awk
来限制透明大页面的输出?
透明大页面的示例输出:
$ cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
我需要输出到:
never
答案 0 :(得分:1)
关注awk
也可以帮助您。
awk -F"[][]" 'NF{print $2}' Input_file
说明: 以下不是确切的代码,仅供说明之用。
-F"[][]" ##Setting field separator as ] and [ for each line in Input_file.
'NF{ ##Checking condition here if line is NOT NULL where NF is number of fields awk variable which will be set only when a line is NOT NULL.
print $2} ##If above condition is TRUE then print the 2nd field of current line of Input_file.
' Input_file ##Mentioning Input_file name here.
答案 1 :(得分:0)
这样的事情怎么样?
awk -F'[\\]\\[]' '/always madvise/ && NF > 2 { print $2 }' /sys/kernel/mm/transparent_hugepage/enabled