regex - Grep/Sed/Awk a block and search for pattern -


i'm trying grep blocks database pattern.
after wanna grep every block again pattern.
need 1 match every pattern of every block.

file so:

inetnum:        *.*.*.* - *.*.*.* netname:        ch-123 descr:          companyname descr:          address 1 descr:          address 2 descr:          address 3 country:        fr admin-c:        dumy tech-c:         dumy status:         dumy mnt-by:         mnt changed:        nothing@nothing.net created:        1970-01-01t00:00:00z last-modified:  1970-01-01t00:00:00z source:         ripe remarks:        **************************** remarks:        **************************** remarks:        **************************** remarks:        **************************** remarks:        **************************** remarks:        ****************************  % tags relating '*.*.*.* - *.*.*.*' % ripe-registry-resource  inetnum:        *.*.*.* - *.*.*.* netname:        ch-123 descr:          companyname descr:          address 1 descr:          address 2 descr:          address 3 country:        fr admin-c:        dumy tech-c:         dumy status:         dumy mnt-by:         mnt changed:        nothing@nothing.net created:        1970-01-01t00:00:00z last-modified:  1970-01-01t00:00:00z source:         ripe remarks:        **************************** remarks:        **************************** remarks:        **************************** remarks:        **************************** remarks:        **************************** remarks:        ****************************  % tags relating '*.*.*.* - *.*.*.*' % ripe-registry-resource 

so have each block "country: ch" is. after need example of each block 1 result, 1 'descr', 1 'netname', there more, need first 1 companyname.

requirement:

  1. get blocks of file, have "country: ch"
  2. then grep/awk/sed whatever 1 of "inetnum,netname,descr"

output should of each block, "country: ch" is.

*.*.*.* - *.*.*.* ch-123 companyname 

and not:

input:

grep -e "inetnum:        (.*)\n|netname:        (.*)\|descr:          (.*)\n" file 

output:

*.*.*.* - *.*.*.* ch-123 companyname address 1 address 2 address 3 

i every time that. i'm trying regular expression, never used before.

i hope can me.

and: why : sed -n '/inetnum/!b;:a;/% tags relating to/!{$!{n;ba}};{/country: ch/p}' file never end?

awk rescue!

if structure fixed , blocks separated empty line should work

awk -f: -vrs= -vofs=, '$16~/it|de/{print $2,$4,$6}' 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -