我有一个文件具有以下结构的场景:
This is the list of all the employees and their desk numbers
Please dont exchange the chairs or drawers
Handle the furniture around with care
Name Desk No
---- -------
Joe 445
May 560
Sue 669
我只需要获取办公 table 号码。我正在考虑使用 ----
作为过滤器并在后面的文本之后打印第二列。有更好的解决方案吗?
最佳答案
另一种方法:
$ awk 'p{print $2}$1=="----"{p=1}' file
445
560
669
这使用变量 p
作为打印标志(默认值为零)。只有当我们将 p
设置为非零值时, block print $2
才会执行。我们在看到第一个字段为 -----
的行后设置 p
。
关于linux - 在标题后打印文件中的第二个字段。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15271218/