繁体   English   中英

Unix命令将文件内容附加到文件列表中

[英]Unix command to append the content of files in a file list

我有一个文件中102个文件位置的列表。 我必须将列表中每个文件的内容合并到一个文件中。

在文件列表中,每行包含一个文件名。

请帮我找一个在UNIX环境中执行此操作的方法。

这可以工作:

while read file
do
   cat $file >> new_file
done < your_file_with_names

$ cat file1
aaa1
$ cat file2
aaa2
$ cat file3
aaa3
$ cat a
file1
file2
file3
$ while read file; do cat $file >> new_file; done < a

结果:

$ cat new_file 
aaa1
aaa2
aaa3

也许在for loop

LISTFILE="/path/to/file/with/list"
RESULTFILE="/path/to/result/file"


if test -f $RESULTFILE; then
  rm $RESULTFILE;
fi

for f in `cat $LISTFILE`; do
  cat $f >> $RESULTFILE;
done

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM