concatenate files including path in header - path contains spaces
Posted
by
manolo
on Super User
See other posts from Super User
or by manolo
Published on 2012-08-29T19:07:11Z
Indexed on
2012/08/29
21:41 UTC
Read the original article
Hit count: 328
I have to concatenate a number of files in a directory structure which contains spaces in the folder names looking like this: ./CH 0000100014/A10/11XT/11xt#001.csv
find . -name "*.csv" -type f -print0 | xargs -0 cat > allmycsv.txt
does the job, however now I need to include the information contained in the path, i.e. CH 0000100014/A10/11XT
as a header of each inputfile to cat.
find . -name "*.csv" -type f -print0 | xargs -0 -I % sh -c 'echo %; cat %' >allmycsv.txt
would do the job, if I had no spaces in the path, but in my case, cat does not get along with the space in the path name. Is there a way out?
Cheers, E
P.S. I am working on bash on OSX
© Super User or respective owner