I find it hard to believe this question has never been asked before on this forum:
How do you get find to print (return, echo, export, vomit, expel, proclaim; your choice of verb over mine) ONLY the first match it finds in a directory or directory hierarchy?
I'm trying to re-assemble a list of files that reside in several subdirectories of one main directory. The list I am using was generated using a script that matched a four-number substring to a label in another list; the former file had 5750 lines and the latter nearly 5300, so you can understand why I don't simply run the script, slightly tweaked, on the first list and just use a 'cut column a from b' kind of script on that one. The second list took (at minimum) 2 1/2 hours to generate in GNOME Terminal.
So approaching it from the other end -- the two lists -- I've discovered that I have a main list with filenames that match files in more than one subdirectory. This is the reason I want to use find, or a builtin that's no doubt less elegant but more useful, to match and return only the first instance. I believe the original "master" list was "run once through the sort
wringer" with a -u option so only has the first instances of every filename.
Originally Posted by Codes and Examples
'find' comes upon a line like this:
and gives this as a return:
The list generated by the script I'm using now to reconstruct full-path matches had this happen nine times (not a visual count but a grep, wc -l
return) before I interrupted the script with ctrl-c. At that point it had written 325 lines.