我正在递归地将目录中的文件连接在一起,但是有些文件在最后一行后面缺少换行符,这会导致问题。
在过程中如何为每个文件追加一个换行符?这是脚本:
find $1 -type f |xargs cat > test.csv
修改后的脚本如下:
find $1 -type f |xargs awk '1' > test.csv
for i in *; do cat "$i" && echo ""; done
find $1 -type f | while IFS= read -r file
do
cat "$file"
echo
done > test.csv
find $1 -type f |xargs awk 'FNR==1 && NR>1 {print ""} {print}'
或者
find $1 -type f |xargs awk 'ENDFILE {print ""} {print}'
for f in `find $1 -type f`; do sed -E '$s/(.*\S+.*)/\1\n/' $f; done
编辑:我的第一个答案使用了xargs,但是没有提供预期的结果,所以退而求其次使用了循环。
for file in $(find .); do cat $file >> huge_file; echo " " >> huge_file; done