This awk
should do:
arr=($(awk '/^server_name/ {f=1} f {p=$NF;sub(/;$/,"",p);print p} /;$/ {f=0}' file))
echo ${arr[0]}
example.com
echo ${arr[1]}
www.example.com
echo ${arr[2]}
anothername.co.uk
It will get all text starting form server_name
and ends with ;
into an bash array
Or you can store them in an internal awk
array, and then write them to another file:
awk '/^server_name/ {f=1} f {p=$NF;sub(/;$/,"",p);a[++c]=p} /;$/ {f=0} END {for (i=1;i<=c;i++) print a[i]}' file > newfile
cat newfile
example.com
www.example.com
anothername.co.uk