Issue
I have searched the web (here) and searched in SO as well, but i didnt understand why grep fails to match lines end with the anchor $
my input file
f_Hndlr_foo=0xd0001244 0x4
f_Doj_cmdmem=0x7ffe8710 0x44
f_Doj_getHif=0xd0001248 0x4
f_tpl_geBufferPtr_rom=0x7ffe8754 0x6A
f_tDoj_cmdmem=0x7ffe8710 0x21
f_tDoj_getHif=0xd0001248 0x43
f_tpl_geBufferPtr_rom=0x7ffe8754 0x21A
I need to match the lines that end in 0x4
only! I have called grep
with all the froms below and nothing match and extract the lines i need! what i am doing wrong?
grep -E "0x4$" "C:\Users\user\Desktop\foo.txt"
grep -E ".0x4$" "C:\Users\user\Desktop\foo.txt"
grep -E " 0x4$" "C:\Users\user\Desktop\foo.txt"
grep -E 0x4$ "C:\Users\user\Desktop\foo.txt"
I am runing on win7 comand line. the grep version is: grep (GNU grep) 3.1
Solution
Because grep expect an Unix like line ending, you need :
grep '0x4[[:cntrl:]]*$' Input_File
Or consider passing dox2unix
tool on the file before to do it simpler.
Check: https://unix.stackexchange.com/a/176505/12574
Answered By - Gilles Quenot