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
Post a Comment