我在一个目录下有50000多个文件,比如file1.txt、file2.txt、.....、file50000.txt。我想连接一些文件,其文件号列在以下文本文件 (need.txt) 中。
need.txt
1
4
35
45
71
.
.
.
我尝试了以下内容。虽然它有效,但我正在寻找更简单、更快捷的方法。
n1=1
n2=$(wc -l < need.txt)
while [ $n1 -le $n2 ]
do
f1=$(awk 'NR=="$n1" {print $1}' need.txt)
cat file$f1.txt >> out.txt
(( n1++ ))
done
最佳答案
这也可能对你有用:
sed 's/.*/file&.txt/' < need.txt | xargs cat > out.txt
关于linux - 从 Shell 中的目录连接大量选择性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31538918/