[英]how to grep and write in to new file
I want to read file key value from one file and grep that value from another file(file2) and write the entire content of file2 in to file3, how can I achieve it? 我想从一个文件中读取文件密钥值,然后从另一个文件(file2)中复制该值,然后将file2的全部内容写入file3中,我该如何实现?
file1 : 12345 file2 : abc12345 abc12456 文件1:12345 文件2:ABC12345 abc12456
Expected out put in file3 : abc12345 有望走出放在文件3:ABC12345
This is code I am using 这是我正在使用的代码
while IFS= read -r LINE; do echo $LINE
grep '$LINE' $FILE2 >> $FILE3
done < $FILE1
This should read space separated keys file: "file1" to grep "file2" and if some found write content of "file2" to "file3". 这应该读取以空格分隔的密钥文件:“ file1”到grep“ file2”,如果发现有人将“ file2”的内容写入“ file3”。
#!/bin/sh
IFS=' ' read -r -a FKEYS <<< `cat ./file1`
for next_key in ${FKEYS[@]}; do
if [ "$next_key" != "" ]; then
RESULT=`grep $next_key ./file2`
if [ "$RESULT" != "" ]; then
echo $RESULT > ./file3
exit
fi
fi
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.