regex - Grep fixed word and end of line character -


i'm writing bash script , print lines containing word, if @ end of line. given file this:

d41d8cd98f00b204e9800998ecf8427e  ./12/2.txt d41d8cd98f00b204e9800998ecf8427e  ./12/1 d41d8cd98f00b204e9800998ecf8427e  ./12/1.txt d41d8cd98f00b204e9800998ecf8427e  ./1 d41d8cd98f00b204e9800998ecf8427e  ./11.txt 

and given word equal "./1" print line:

717c41ff4049b0e8cbdc7ec7e49ad021  ./1 

i'd use grep, "$" anchor added @ end, problem words may contain dots need have -f option, unsure how secure printed lines contain word @ end of line, can't use line anchors.

edit: word passed variable not fixed string.

you can use awk if definition of word means white-space separated given in sample input

$ awk '$nf == "./1"' ip.txt  d41d8cd98f00b204e9800998ecf8427e  ./1 

this print lines last field equal string ./1

no need worry escaping regex meta characters if search word changes


pass shell variable:

$ s='./1' $ awk -v word="$s" '$nf == word' ip.txt  d41d8cd98f00b204e9800998ecf8427e  ./1 

see how use shell variables in awk script?


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -