![grep 返回空响应](https://linux22.com/image/15407/grep%20%E8%BF%94%E5%9B%9E%E7%A9%BA%E5%93%8D%E5%BA%94.png)
我有下面的代码,它ctakes-backlog-new.lst
逐行读取文件并从文件中 grep 完整匹配的字符串without_symlink.lst
并将结果加载到ctakes-backlog-new.lst
.两个文件均已排序。但是,当运行下面的代码时,我得到空响应。
if [ -z "$1" ]
then
echo "Filename is missing."
usage
exit 1
else
fileName="$1"
fi
while read line;
#echo "$line"
do
grep -w "$line" 06-09-2021/without_symlink.lst >> 06-09-2021/ctakes_full_file_name.lst
done < "$fileName"
我运行的命令:./populate_full_file_name.sh 06-09-2021/ctakes-backlog-new.lst
当我手动运行单行命令时,grep -w "77-010_M0_1_arm_1" 06-09-2021/without_symlink.lst >> 06-09-2021/ctakes_full_file_name.lst
它工作正常并加载结果(77-010_M0_1_arm_1.60c7144c9ff3060521b0b825149f7d7ee60e5afd.pdf)06-09-2021/ctakes-backlog-new.lst
我尝试用"$line"
双引号括起来,但没有任何区别。例如:grep -w "$line" 06-09-2021/without_symlink.lst >> 06-09-2021/ctakes_full_file_name.lst
输入示例:
13-013_M48_9_arm_1
16-039_M42_8_arm_1
77-010_M0_1_arm_1
预期输出:
13-013_M48_9_arm_1.d4b2f31683ba73f7919d46a2514d0742c77029a3.pdf
16-039_M42_8_arm_1.546b57794b71b7a17235368900f5f9c4d34a2a87.pdf
77-010_M0_1_arm_1.60c7144c9ff3060521b0b825149f7d7ee60e5afd.pdf