Monday, October 10, 2022

Some useful grep tricks I keep having to look up

 As I've said, this blog is meant for things I find myself repeatedly doing.  Especially, when I am doing them on different *nix systems I end up googling and eventually finding my same references:

This stackoverflow thread tends to be my main one to use for when I need to look for files containing as specific thing in them.  For instance, I often forget the full syntax in proc means for SAS.  

So I go to my code bases and execute the following:

      find . -name "*.sas" | xargs grep "proc means" | less

I also sometimes need to find files that contain specific things in them and copy them to a specific location.  I found this stackexchange thread useful (although not totally clean yet):

      find . -name "*.sas" | xargs grep -l "proc means" | xargs cp -t ~/destination