-1

OpenVPN log looks like this:

OpenVPN

CLIENT LIST
Updated,Sat Jun 20 04:20:07 2015
Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since
[ A .... ]
ROUTING TABLE
Virtual Address,Common Name,Real Address,Last Ref
[ B.... ]
GLOBAL STATS
Max bcast/mcast queue length,33
END

Where A and B above are lists of hosts formatted in a certain way.

I have a bash script that I will use to act on the items in the part called "ROUTING TABLE" (B). How can I separate this list of hosts from the rest of the document in an efficient manner in my script?

0

2 Answers 2

1

You can used sed to delete (d) lines from line 1 to the matching start line. Then delete lines from the matching end line to the last line ($). You probably also want to delete the "Virtual Address" header line too. All that's left is what you want!

sed '1,/^ROUTING TABLE/d
     /^Virtual Address,/d
     /^GLOBAL STATS/,$d'
1
  • This made the most sense to me so you get the vote. Jun 20, 2015 at 18:33
1

The following sed command

      sed -n '/ROUTING/,/\[ B/{p}' filename

does what you wish: the -n suppresses the default behaviour which is to print every line, the expression between single quotes selects a range of lines, then prints them (this is the meaning of {p}). The ranges to be selected are identified by means of matches (the initial and final one) delimited by separatrices, in my case I use the forward slash / as separatrix; the initial and final pattern match must be separated by a comma, and \[ is used to stress the literal meaning of the square parenthesis, i.e. this is not a grammatical structure but instead it is a real opening square parenthesis which must be found.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .