awk - Grep (fgrep) bash exact match end of line -
i have below example file
d41d8cd98f00b204e9800998ecf8427e /home/abid/testing/filenamestest/apersand $ file d41d8cd98f00b204e9800998ecf8427e /home/abid/testing/filenamestest/file[with square brackets] d41d8cd98f00b204e9800998ecf8427e /home/abid/testing/filenamestest/~$tempfile 017a3635ccb76250b2036d6aea330c80 /home/abid/testing/filenamestest/filethree 217a3635ccb76250b2036d6aea330c80 /home/abid/testing/filenamestest/filethreedays d41d8cd98f00b204e9800998ecf8427e /home/abid/testing/filenamestest/single quote's
i want grep last part of file (the file name) i'm after exact match last part of line (the file name)
grep filethree$ files.md5 017a3635ccb76250b2036d6aea330c80 /home/abid/testing/filenamestest/filethree
gives exact match , doesnt find "filethreedays" i'm after because of file names contains square brackets i'm having use grep -f or fgrep. using fgrep above doesnt work returns nothing.
how can exact match last part of line using fgrep whilst still honoring special characters above ~ / $ / ' / [ ] etc...or other method using maybe awk...
further....
using fgrep withou return both these files want exact match (using use of $ above grep), $ fgrep doesnt return anything.
grep -f filethree files.md5 017a3635ccb76250b2036d6aea330c80 /home/abid/testing/filenamestest/filethree 217a3635ccb76250b2036d6aea330c80 /home/abid/testing/filenamestest/filethreedays
i can't tell details question, sounds can use grep , escape special characters: grep 'file\[three\]days$'
if want use fgrep
, though, can use tr
tricks you. if want filename (without directory name), can like
cat files.md5 | tr '/' '\n' | fgrep filethreedays
that tr
command replaces slashes newlines, put each filename on own line. means fgrep
find filename when searches filethreedays.
if want full filename directory, it's little trickier, similar approach work. assuming there's double space between sha , filename, , there aren't filenames double spaces or tab characters in them, can try this:
sed 's/ /\t' files.md5 | tr '\t' '\n' | fgrep filethreedays
that sed
command converts double spaces tabs. tr
command turns tabs newlines (the same trick above).
Comments
Post a Comment