shell - how to grep the last occurrence of the line pattern -
i have file contents,
x x b x c i want grep last occurrence,
x c when try
sed -n "/x/,/b/p" file it lists lines. beginning x c
i'm not sure if got question right, here answers:
print last occurence of
x:grep x file | tail -1print input lines beginning first matching line:
awk "/x/ { flag = 1 }; flag" txtprint lines beginning last matching line (prints lines if no match found):
tac file | awk "!flag; /x/ { flag = 1 }; " | tac
Comments
Post a Comment