比较文件脚本

比较文件脚本

我正在使用此脚本来查找存储在一个文件中的信息,并使用其他文件作为要查找的变量的源:

#!/bin/bash
clear
file=/home/victor/Documentos/Temporal/13-06-04_Cuentas_para_revisar_cajas.txt
while IFS= read -r line
do
echo $line
cat Inventory.csv | grep "$line" >> cuentasxcajas.txt
done < $file
echo "done"

但文件cuentasxcajas.txt是空的,有什么建议吗?

答案1

如果我要完成你的任务,我会这样做:

grep -f '/home/victor/Documentos/Temporal/13-06-04_Cuentas_para_revisar_cajas.txt' -- Inventory.csv > cuentasxcajas.txt

无需 Bash 脚本、for 循环或无用的 cats 用法。只需确保文件中没有空行即可/home/victor/Documentos/Temporal/13-06-04_Cuentas_para_revisar_cajas.txt

相关内容