【发布时间】:2021-04-01 10:24:16
【问题描述】:
我需要在 bash 中获取文件的内容,但我只需要在关键字之前的特定单词。
文件如下所示:
conn NameOfConnection1
some settings
conn NameOfConnection2
some settings
conn NameOfConnection3
some settings
我需要一个 bash 脚本,每行只输出 NameOfConnection1,2,3。
//编辑:
小问题。该文件有这个:
# It is best to add your IPsec connections as separate files in /etc/ipsec.d/
include /etc/ipsec.d/*.conf
并且一些 conns 在单独的文件夹中。
【问题讨论】:
-
grep好像是工具,你试过了吗?