shell脚本-两个list查找匹配项

发布时间 2023-12-05 15:26:09作者: 容_易
#!/bin/bash

search_list='xx/search_list.txt'
list='xx/revise_list.txt'
result='xx/result.txt'

# 逐行读取list文件
while IFS= read -r line; do
  # 在search_list文件中查找匹配项
  match=$(grep -F "$line" "$search_list")
  
  # 如果有匹配项,则写入到result文件,否则写入not match
  if [ -n "$match" ]; then
    echo "match ${line}" >> "$result"
  else
    echo "not match ${line}" >> "$result"
  fi
done < "$list"