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.
2
Answers
Here is a solution:
Using
awk
can print/extract the desired output.the above code basically means, If field/column
$1
isconn
then print the second$2
field/column.