Re:Posix Has Become Outdated (2016) [pdf]
by hawski on Saturday February 11, 2017 @01:21PM
(#13623882)
You probably could use process substitution to get rid of the temp file:
comm -12 Whitelist <(ag MyString | awk -F: '{print $1}' | sort | uniq) > Output
Then you could use unique flag of sort: comm -12 Whitelist <(ag MyString | awk -F: '{print $1}' | sort -u) > Output
Also ag can list only matching files (getting rid of awk and unique): comm -12 Whitelist <(ag -l MyString | sort) > Output
Re:Posix Has Become Outdated (2016) [pdf]
by umanwizard on Saturday February 11, 2017 @01:48PM
(#13624054)
Thanks for the tips!
Re:Posix Has Become Outdated (2016) [pdf]
by pjmlp on Saturday February 11, 2017 @03:25PM
(#13624600)
Apparently you forgot to read the part where I mentioned "Languages like Python?".
import glob
import shutil
whitelist = set(open('Whitelist').read().split())
for fd in [ x for x in glob.glob('mydir/*', recursive=True) if x in whitelist]:
shutil.copy(fd, 'OUTPUT')
Better, no need to create temporary files.
Re:Posix Has Become Outdated (2016) [pdf]
by belltaco on Saturday February 11, 2017 @02:33PM
(#13624289)
Would be trivial to write a GUI program to do the same.
Re:Posix Has Become Outdated (2016) [pdf]
by umanwizard on Saturday February 11, 2017 @02:52PM
(#13624395)
I think it would take at least a half hour, unless you have directory traversal, file I/O, and regex APIs memorized which most people don't. That's "trivial" in the grand scheme of things but it's really not practical to do day-in and day-out every time some random scripting necessity arises.
And you presumably have to clutter up your filesystem with random project files, etc, which is annoying. Are you going to have 1000 of these, one for every time you need to do some sort of minor task like this?
That command, on the other hand, took me 2 or 3 minutes to write, and I had to look up the syntax for `mktemp`. If I had remembered the mktemp syntax it would have taken a few seconds.
Find all files containing a particular string in a directory tree. For each of those files, if its filename appears in a file called Whitelist, write it to a file called Output. Otherwise, do nothing.
Here is one possible command line version (I haven't tested it as I'm on mobile):
TMPF=`mktemp /tmp/XXXXXXXX` && ag MyString | awk -F: '{print $1}' | sort | uniq > $TMPF && comm -12 Whitelist $TMPF > Output && rm $TMPF