我有2个文件
#cat file.txt
aaa
bbb
ccc
#cat input.txt
191
112
339
我需要
#cat output
aaa,191
bbb,112
ccc,339
我正在尝试
while IFS= read -r line
do
cat file.txt | grep "\.$line$" | wc -l >> output.txt
sed -i "1 i\\$line" output.txt
done < input.txt
但是它会打印组中每个文件的所有行。
知道如何存档结果吗?
如果您是喜欢写多行而不是少行的类型,可以尝试以下方法:
echo -n "" > output.txt
while IFS= read -r line_input && IFS= read -r line_file <&3
do
echo "$line_input,$line_file" >> output.txt
done <input.txt 3<file.txt
如果没有,您可以简单地使用@ RavinderSingh13提示;-)