find and cat to merge csv files

让人想犯罪 __ 提交于 2019-12-11 10:02:47

问题


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


来源:https://stackoverflow.com/questions/12790231/find-and-cat-to-merge-csv-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!