Python Forum
script to filter python files - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Code sharing (https://python-forum.io/forum-5.html)
+--- Thread: script to filter python files (/thread-740.html)



script to filter python files - Skaperen - Nov-02-2016

i was doing this in grep a lot so i made this little script and put it at /usr/local/bin/pygrep.


so now i use the script a lot.


RE: script to filter python files - micseydel - Nov-02-2016

Could you elaborate on the benefit(s) of this?


RE: script to filter python files - Ofnuts - Nov-02-2016

Also curious... and why not an alias anyway.


RE: script to filter python files - Skaperen - Nov-03-2016

(Nov-02-2016, 03:33 PM)micseydel Wrote: Could you elaborate on the benefit(s) of this?

i, personally, scan for files a lot with pipelines to work with very large lists (i currently have around 6000000 files in the /home directories.  filtering specific file types makes for faster content searches and gives me less noise.

for many people, there may be no benefit at all.

(Nov-02-2016, 06:17 PM)Ofnuts Wrote: Also curious... and why not an alias anyway.

it could have been an alias.  but i have many times run into cases where filtering file paths like this is not running under a shell, or initializing the shell to have all my aliases (there would be many if i did this as aliases or shell functions) is not always practical.  i have done many of these as shell scripts and they are under my working plans to convert most shell scripts to python3.  when i write new scripts, now, i try to do them in python3 first, falling back to python2, pike, awk, bash and C (in that order) if there are problems (had one, once, but re-did it in python3 later).  simple aliase-like commands like this are trivial and have never had problems.

i just rewrote it to take symlinks for many languages/extension:


then i did:

ln -fsv grepext /usr/local/bin/pygrep
and some others.  symlinks still take filesystem space and cache memory so there is still no real gain.