grep – show lines until certain pattern - Ask Ubuntu
this question has answer here:
i on ubuntu 16.04 , want search files let’s “if” , want output until “endif”. file this
if … code endif i can grep -a9 if my_file | grep -b9 endif. doesn’t works if “if” clause larger 9 , if several “if” clauses in same file , if first grep command contains several “if” clauses. option -m1 in second grep doesn’t help. nested “if” clauses can ignored. has idea, maybe not grep?
difference how grep multiple patterns on multiple lines?
the question asks solution
grepanswered in question:grep -a9 if my_file | grep -b9 endif. solution doesn’t work in case work in case of other question.the proposed grep solutions of other question don’t work (with ubuntu?):
grep: ein nicht geschütztes ^ oder $ wird mit -pz nicht unterstützt.grep: not protected ^ or $ not supported -pz. use following:root:/tmp# cat file text begin text goes here. end more text root:/tmp# grep -pzo "^begin\$(.|\n)*^end$" file grep: ein nicht geschütztes ^ oder $ wird mit -pz nicht unterstütztthe proposed solutions search pattern start @ beginning of line if interpret proposed solution correctly. if remove
^command doen't work.
you can use sed that:
sed -n '/if/,/endif/p' myfile -ndon't print until ask it/if/find first line this,keep going until.../endif/last line wantpprint matched lines
Comments
Post a Comment