如何仅打印前后包含空行的行
我如何只打印line(s)前后包含空白的行。我正在尝试各种 awk 和 grep 组合,但不知何故无法获得它。
tuv0657
tuv2330
tuv2133 Unable to get the ssh connection
tuv1988 Unable to get the ssh connection
tuv1049
tuv1683 Unable to get the ssh connection
tuv2101
期望:
tuv0657
tuv1049
tuv2330
tuv2101
我试过的:
我在下面试过但没有得到结果..
$ awk '{if ($2=="") print $0}' file
$ grep -E --line-number --with-filename '^$'
回答
使用您显示的样本,您能否尝试以下操作。
awk -v RS="" 'NF==1' Input_file
tuv0657
tuv2330
tuv1049
tuv2101
- @user294110, sure, shortest explanation will be: Setting RS to paragraph mode and then checking if field is only 1 then print that line simply 🙂 will add it in my answer in my few mins or so, cheers.