I'd like to run two piped commands on the results of find
on some nested csv files, but I miserably fail.
Here is the idea:
$ find ./tmp/*/ -name '*.csv' -exec tail -n +2 {} | wc -l \;
in order not to count the header row of each CSV file.
The command is failing on:
wc: ';': No such file or directory
find: missing argument to `-exec'
Do I really need to do a for
loop in that case?
E.g.:
$ for f in ./tmp/*/*.csv; do tail -n +2 ${f} | wc -l; done
but with that I'm losing the nice output of find
which does include the filename along the count.
I'm also losing the file name when using this solution: pipe commands inside find -exec?
$ find ./tmp/*/ -type f -name "*.csv" -print0 | while IFS= read -d '' f; do tail -n +2 "${f}" | wc -l; done
A little precision; when I speak about the filename that gets printed, it's because I'm used to the following result when calling the commands on a single file:
$ tail -n +2 | wc -l ./tmp/myfile.csv
2434 ./tmp/myfile.csv
I use Ubuntu 18.04.
tail -n +2 | wc -l ./tmp/myfile.csv
? Itswc
does not read from the pipe. (... | wc -l
or... | wc -l file -
would, but the former won't print the name of the file(s) whose lines come fro the pipe, while the latter won't readfile
's lines from the pipe). – fra-san Feb 28 '21 at 11:42