$mod = "ABC "; $hier = `tac temp.xx | sed -n '/$mod /,/YYY/ p'| grep XXX`; #### %tac temp.xx | sed -n '/ABC /,/YYY/ p' | grep XXX XXX ZZZZ