刚刚开始接触shell,用以处理工作中一些小问题
今天写了一个脚本,代码如下:
#!/bin/bash
zcat $1 | awk -F\" '{print $8}'|sort|uniq -c|sort -r|awk '{print $2,$1}' >ips.txt
cat ips.txt | while read line
do
A=(`echo $line`)
B=`nslookup ${A[0]}`
if [[ "$B" =~ "baidu" ]]
then
echo ${A[@]} "真"
else
echo ${A[@]} "假"
fi
done >iprst.log
rm ips.txt
脚本运行过程需要生成一个ips.txt文件,最后又删除。这种只在运行过程中需要用到的文件,我称之为中间文件。
在使用shell解决其他问题时也经常遇到这种情况,有时候甚至需要用到2~3个这种中间文件。
请问,有什么方法可以减少这类文件的使用,让代码更简洁呢?
嵌入式文档如何应用到以上脚本中?
管道本身就可以解决这种问题,以上面的代码为例,完全可以这样写: