cat 多个 txt 文件后换行
newline after cat multiple txt files
我正在尝试使用 bash 从几个单行文本文件中读取数据,每个文本文件都在其自己的目录中,然后将它们吐出到一个主文件中,每个文件占一个新行。
我的输入文件的数据结构如下;
Store# online backoffice win7
我正在循环遍历每个目录,查找并将文件内容分类为一个变量。问题是我似乎无法让每一次传递都将数据放在换行符上。这是我的代码;
#!/bin/bash
#Find all sites
stores=$(find /home/sites*/ -maxdepth 0)
for store in $stores; do
final=${final}$(cat ${store}\processors.txt)"\n"
done
printf "${final}" > ~/master.txt
我在主文件中得到的是
Store# online backoffice win7Store# online backoffice win7
您可以用一行代码替换您的脚本:
find /home/sites* -name "processors.txt" -exec cat {} + > ~/master.txt
由于您将在 windows 机器上阅读,您可能需要在行尾插入 return 回车:
find /home/sites* -name "processors.txt" -exec cat {} + | sed -e 's/$/\r/' > ~/master.txt
我正在尝试使用 bash 从几个单行文本文件中读取数据,每个文本文件都在其自己的目录中,然后将它们吐出到一个主文件中,每个文件占一个新行。
我的输入文件的数据结构如下;
Store# online backoffice win7
我正在循环遍历每个目录,查找并将文件内容分类为一个变量。问题是我似乎无法让每一次传递都将数据放在换行符上。这是我的代码;
#!/bin/bash
#Find all sites
stores=$(find /home/sites*/ -maxdepth 0)
for store in $stores; do
final=${final}$(cat ${store}\processors.txt)"\n"
done
printf "${final}" > ~/master.txt
我在主文件中得到的是
Store# online backoffice win7Store# online backoffice win7
您可以用一行代码替换您的脚本:
find /home/sites* -name "processors.txt" -exec cat {} + > ~/master.txt
由于您将在 windows 机器上阅读,您可能需要在行尾插入 return 回车:
find /home/sites* -name "processors.txt" -exec cat {} + | sed -e 's/$/\r/' > ~/master.txt