首页 > 解决方案 > 使用 awk 限制透明大页面的输出

问题描述

我将如何awk过滤透明大页面的当前设置?

透明大页面的示例输出:

$ cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]

我只想输出当前设置:

never

标签: awk

解决方案


以下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.

推荐阅读