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.
find -type f -name '*.csv' -exec ...
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)
@wence started
London Fixed Gear and Single-Speed is a community of predominantly fixed gear and single-speed cyclists in and around London, UK.
This site is supported almost exclusively by donations. Please consider donating a small amount regularly.
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)