我需要你的帮助。
我有一个包含很多行的文本文件,我想为每一行提取一个代码。 此代码位于两种模式之间:
1)“隔离”
2)“,”
我的 log.txt 示例:
George Thibault give two balls quarantine: x27041992, to someone
Edward Thin give three PC'S quarantine : m5405051993, to Fed
Tommy Dijoux give one shoe quarantine : cD001252000, to luc
新文件中想要的结果:
x27041992
m5405051993
cD001252000
有人可以帮助我吗?
请您参考如下方法:
尝试使用以下 bash 脚本
#!/bin/bash
>output
while read line; do
for word in $line; do
if [[ $word == *","* ]]; then
echo ${word::-1} >> output
fi
done
done < gr
注意:使用 shell 循环处理文本文件不是一个好的做法。 read this