You are reading a single comment by @wence and its replies. Click here to read the full conversation.
  • If you're willing to install fd (github.com/sharkdp/fd), and you don't care about the order of the output, then:

    fd -t f -e csv -x sed 's/^/{/},/; 5q' {}

    does the trick and is safe to spaces etc in file names.

    If you want the full path name in the output it's trickier because that would have a / in it which will confuse sed.

    Or, with awk, full filename:

    fd -t f -e csv -x awk '{printf("%s,%s\n", FILENAME, $0); FNR == 5 {exit}' {}

    then you could also just use find -type f -name '*.csv' -exec ... instead too.

    Note the exit in the awk command which stops reading the file after 5 lines (so if you have a very long file it doesn't need to read all of it)

About

Avatar for wence @wence started