WoofyDugfock
Group: Members
Posts: 146
Joined: Sep. 2004 |
|
Posted: April 30 2005,16:31 |
|
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.
-------------- "We don't need no stinkin' Windows"
http://news.zdnet.co.uk/software/linuxunix/0,39020390,39149796,00.htm
|