DSL Ideas and Suggestions :: "Add to filetool.lst" button
hey...that's cool. I'd never heard of 'join'...or 'done'. gonna need to read some more =o)
could you please verify a few things? (these are assumptions): %d = `pwd` join replaces grep done checks the exit status of the last command
It looks like it's doing more work, but if it's faster it's better =o)Thx, I wouldn't have heard of `join' either except it was mentioned in passing recently in Linux Magazine (though they didn't use it this way) and I've been working hard on my bash (slow period at work!).
Quote
could you please verify a few things? (these are assumptions): %d = `pwd` join replaces grep done checks the exit status of the last command
%d returns the active directory from emelfm while %f returns the basename of the file selected (emelfm help page) - so in this case the same result as `pwd`.
join file1 file 2 -- compares lines in both files, actually the default is to compare the first field in the line that ends with the first whitespace (ie in our case this compares whole lines). If there is a match, it will append the remainder of the matching line in one file to the line in the other, except if the line in file 1 is identical to that in file 2 there's nothing to append and it won't double that line to output (so if the line is already in filetool.lst it won't be duplicated to stdout). One of these files can be stdin `-' ie the output from a pipe. If there is no match it won't return anything, unless you use option `-a filenumber' ("append"), in which case it will append all of file1 to output. Since we use -a for both files, it will write the contents of both stdin and $a to the temp file, which then overwrites filetool.lst ie the line is written to filetool.lst just as desired. So used here, in short, it does replace "(test) grep pattern append || don't append ", but it's in one command. Clear as mud, I know. Took me a bit of thought, I haven't seen this anywhere (although it'd have to be around).
The "done" is just the "done" that terminates the "for" loop.
Though this use of "join" looks nice, I expected it to be slower than either Mik's grep test version or using "cat - $a|sort|uniq" (my first attempt - same result as join here except join puts the new lines at the beginning of filetool.lst) - but putting`time` in front of it suggested otherwise.heh...i should have realized what "done" is. From my first pre-coffee look, i was thinking it was an additional command =op
One thing to consider, though i don't know the whole story.... filetool.lst is executable. I'm not sure why, but i assume there's a reason for it. Does your script overwrite this permission when it overwrites the file?Hang on I've gotta think about itYou must have been reading my thoughts because it occurred to me that overwriting filetool.lst was DUMB and redundant, let alone that temp file. Just where does my brain go when it's not there? Dunno, I can't find it to tell me !!
I have a verson that doesn't use the temp file or overwrite filetool.lst either, but it's buggy and I've about had it for today.
Does anybody else think it's worth chewing on/comparing implementations like this - after all, if-grep does work ....? Regardless I intend to try to use this join trick to speed up a long script I'm writing that currently 'if-greps-appends-else' a lot on largish files....Next Page...
original here.