I ended up using ripgrep which is available in the standard Ubuntu package repositories from 18.04 on: rg -i "pattern" There are alternatives to grep like ugrep or ripgrep that (among other things) can handle utf-16 files. This is of course very limited in terms of possible patterns. There are different solutions, two of which I am going to shortly describe here:Ī quick-and-dirty solution that worked for me was to expand the search pattern to include one that would match the utf-16 version and search for one of both patterns: grep -riPa. However, the remedy of converting utf-16 files to utf-8 before grep does not work when I use it recursively, as I don't know beforehand which files may be utf-8 and which utf-16 and a am searching through a lot of files. So, the problem is that my grep does not work on utf-16 encoded files. Executing :set fileencoding in vim also correctly displayed fileencoding=utf-16 (found here ). I failed to recognize that the utf-8 shown by vim were actually the buffer encoding, not the file encoding. Identified it as text/plain charset=utf-16be. So, double-checking the encoding with file -i file_for_which_grep_fails.txt I learned this using hexdump (credits to hd file_for_which_grep_works_as_expected.txt The files 'grep' did not show any output for were not actually utf-8 encoded, but utf-16be. If you have any questions, please let me know.I found the problem (with the help of another answer). Maybe I’m still thinking too much like a DOS user. Recursing not supposed to, AFAIK depend upon the file type that fgrep is searching in. Read all files under each directory, recursively this is I’m thinking that fgrep should recurse when *.txt is specified as a file type (and there are no *.txt files in the root dir).Īccording to the man pages, the fgrep -r option should: The same disfunction occurs when starting from the root directory. fgrep will then traverse the directories recursively and search all files (including both license.txt files in the current directory and sub-directory).This should have, as I understand it, found at least two instances- one in you will see one instance (I think) where ‘public’ is found in the license.txt file.Ħa.This does not seem to be possible with only fgrep. I want to scan only *.txt file type documents. Sorry, but it appears that I was unclear about the original anomaly. Kjg1eAM3vVRLkdSxfEgTqoICk+zGzbGF4v3iP5P5E4E4Egk9ioRvy70KKLOJkElz H1oV6JQiNHeS82aExUomGV4cvfT+phkIgsa3MriS35Uc3gPRg7cEcXDdsOzmWLFqīF/16D69CicX4FdmQ26gEOcxYpH/52DXVYWWCPZJKiBF0WRqGYn+NMm2DWjvKYYx TxMJ4AkERO5qpZFWgf8FUZIew859P9xbi/wqbHPbxzhEK6R/dsvQAmboQQN/gYUt QL1iC2iHyLqwcXlmweNo/4fy/sV644Uua8i/o0dV6DVKz9b5BYur+d9sO11YsQst PsHuldH22mNiPgZv4lhXFTd+4dHeTxqhVcWzZQb/tUPJyQL1k7ZuOAytopneTwYv GcEjWwyApyDzJjKhjHK9FZCQ4OlZ47xOxWozCemGrNJIhbCOWe59+bKbBQ0di5NL PtqeML14vAGlbDEmmIrtmkOTfUZhg2iI5i0tp20EKjY/+0dYwF3tb27WKC+wii4J U6ThFiMM8R4wN/bU811uuqwZkrxmVGcuj/gdyAoHpVVwmXCrlWsGoveYTF6+BMHy IQIcBAEBAgAGBQJMYGC/AAoJEF+XTK08PnB5hnAP/jlbovJrJnsGsBsMYpA350SdĩM+x9U28wolZ2L18k76H1slQjR64HIpg5qP5PBCqgUVR90cZ2Dpb6//0WKsrCYJL > This is on an 11.2 system, upgraded to 11.3 (ran zypper verify to > recursive does not seem to work from root directory. > I am probably missing something very basic. > fgrep: *.txt: No such file or directory ![]() > -also recurses one level and displays all kinds of data A better way to do this, imo, follows:įind / -type f -iname *.txt | xargs grep -in -C 2 ‘print’ You have any directories matching that so then recursion does not happen You are saying to match *.txt, and I doubt
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |