Reputation: 141
I need to get content of file in bash but i only need specific words which are ahead of a key word.
The file looks like this:
conn NameOfConnection1
some settings
conn NameOfConnection2
some settings
conn NameOfConnection3
some settings
I would need a bash script which would output only NameOfConnection1,2,3 on each line.
//EDIT:
Little catch. The file have this:
# It is best to add your IPsec connections as separate files in /etc/ipsec.d/
include /etc/ipsec.d/*.conf
And some conns are in seperate folder.
Upvotes: 0
Views: 490
Reputation: 7801
Using awk
can print/extract the desired output.
awk '$1 == "conn" {print $2}' file.txt
the above code basically means, If field/column $1
is conn
then print the second $2
field/column.
Upvotes: 1