shell - 将搜索值捕获到 unix shell 脚本中的变量中
问题描述
我正在尝试将文件 1 的内容搜索到文件 2 中,如果找到该内容,则存储在 found.csv 文件中或存储在 notfound.csv 文件中
下面是我的代码,
cd /mnt/data/dobiminer/scripts
usage="Usage:sh scriptname.sh 'ToSearchFile' 'MainSearchFile' 'CR' "
Date=`date +%m%d%y%H%M%S`
File=$(<$2)
echo "File Input $2"
echo $File
if [ $# != 3 ]
then
echo $usage
exit 1
else
echo > "$3-Found-$Date.csv"
echo > "$3-NotFound-$Date.csv"
for MasterClip in `cat $1`
do
echo $MasterClip
String=$(echo "$File" | grep -x $MasterClip)
echo $String
if [ -z $String ];
then
echo "NotFound"
echo $MasterClip >> "$3-NotFound-$Date.csv"
else
echo "Found"
echo $MasterClip >> "$3-Found-$Date.csv"
fi
done
fi
我的猜测是下面的代码行不起作用,因为每当我运行代码时,字符串值都是空的。它没有将搜索值捕获到其中。
String=$(echo "$File" | grep -x $MasterClip)
echo $String
我尝试了多种方法,但不确定我哪里出错了。谢谢你的协助
解决方案
推荐阅读
- javascript - Typescript 找不到使用 webpack 别名导入的模块
- r - if 内嵌套 ifelse 语句
- ios - Unity 集成本机应用程序中的 Clang 错误
- shell - 从任务的输出中获取一个值并在 Ansible Playbook 中调试消息
- macos - OSX:关闭 mysql 工作台主窗口后无法打开它
- python - 从opencv中的二维索引数组获取矩形
- html - How to format json file view on html
- gruntjs - Warning: StringMap expected string key Use --force to continue
- git - Import of gitlab project fails in Codenvy
- neo4j - 获取当前数据库中定义的所有关系类型