linux - print matching word after a pattern using grep -


grep '[branch "default"]' -a 3 config | grep -po 'merge = \k\w+' 

this grep command prints "master" want, there way single grep command instead of 2 grep's ? or other solution?

file config has:

.... .... [branch "default"]          remote = origin          merge = master .... .... 

with gnu grep:

grep -zop '\[branch "default"\].*\n.*\n.*merge = \k\w+' filename 

or gnu sed:

sed -n '/\[branch "default"\]/{n;n;s/.*merge = \(\w\+\).*/\1/p}' filename 

output:

 master 

Comments

Popular posts from this blog

java - Ebean enhancement ignores a model -

ubuntu - How to disable Kernel Module Signing in linux -

SQL php on different pages to Insert (mysqli) -