Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    ls|cut -d_ -f1|uniq -u
You win.


I 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

Although more verbose. I think I prefer omitting the explicit if, though - and just using "test" and "or" ("[[", "||" ).


This 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.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: