awk - Shell script to search for a word in a while block of the C program -
i want search word "while" in file , if file contains word in given block of while need search word "hello" if hello nowadays line no should printed.
please help in regard in advance.
some this?
cat file hi bloc may have while word here hello in block have while not other word awk -v rs="" '/while/ && /hello/' file bloc may have while word here hello
here each block separated empty line. create awk work in block modus, set rs nothing. search line both while , hello
if search while in whole file, , if found, print block hello, do:
awk -v rs="" 'fnr==nr && /while/ {f=1;next} f && /hello/' file file this reads file 2 times. first time search while , if found set f sec time, if f true, , hello found, print block.
shell awk sed scripting
No comments:
Post a Comment