4 ms·
You could use uniq -u to avoid the awk.
by taviso 8y ago
You could use uniq -u to avoid the awk.
- zimpenfish 8y agoPerfect, ta.
- maratc 8y agols|cut -d_ -f1|uniq -u You win.
- e12e 8y agoI like this solution - I'm not very used to using "cut" - or more generally to map from "files" to "fields/lines in a text stream". I'm more inclined to ask: given a list of files with this name, does a file of a different name exist on the file system? But the more Unix approach is really: how can I model my data as a text stream, and how can I then pose/answer my question? (here: list all filenames in folder in sorted order - cut away the text indicating type - then count/display the non-repeat/single entries) My solution would probably be more like (with bash in mind, most of this could be "expanded" to fork out to more utils, like "basename -s" etc) : for data_file in *_data.csv do; alg_file="${data_file%_data.csv}_A.csv"; if [[ ! -f "${alg_file}" ]]; then echo "Missing alg file:\ ${alg_file} for data \ file: ${data_file}"; fi; done Ed: this is essentially the same solution as: https://news.ycombinator.com/item?id=19161358 https://news.ycombinator.com/item?id=19161358 Although more verbose. I think I prefer omitting the explicit if, though - and just using "test" and "or" ("[[", "||" ).
- mnaydin 8y agoThis can be more shortened to ls -1 | uniq -u -w4 using GNU uniq, for these special filenames. Unfortunately, Posix does not define -w option for uniq.