find and cat to merge csv files

2019-08-06 05:13发布

问题:

I have thousands of files in sub-directories of ~/data. I wish to merge all those csv files with a certain extension say .x and save the merged file to ~/data/merged.x

I know I need to use find,cat and >> with the option -iname, but I'm finding it hard to do.

Thanks in advance

回答1:

find ~/data -name "*.x" | while read file
do
    cat $file >> ~/data/merged.x
done


回答2:

find ~/data -type f ! -name 'merged.x' -a -name '*.x' -exec cat {} \+ >> ~/data/merged.x


回答3:

find ./data/ -type f -name "*.c*" | xargs cat > ~/data/merged.x


标签: shell find cat