我需要在 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 '^conn' file.txt | cut -d ' ' -f 2
关于linux - Bash - 获取文件的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66902772/