shell中与运算 cut切分行 if while综合在一起的一个例子

前言:

公司要统计 treasury库hive表磁盘空间,写了个脚本,如下:

查询hive仓库表占用hdfs文件大小:

hadoop fs -du -h  /user/hive/warehouse/treasury.db  > treasury.txt

脚本:

#!/bin/sh
#
while read line
do
size=$1
num=` echo $line | cut -d " " -f 1`
unit=` echo $line | cut -d " " -f 2`
num1=` echo $num | cut -d "." -f 1`
#echo $num1
 
if [ $unit == "G" ]; then
 if [  $num1 -gt $size ]; then
#echo $unit
#echo $num1
 echo $line
 fi
fi
done < treasury.txt

调用命令:

sh filter2.sh  100   表示只过滤大于100G的表调用命令:

 

 

其中上面两个if判断 脚本可以修改成:

if  [[ $unit == "G" ]] && [[ $num1 > 5 ]] ; then

 

 

 

猜你喜欢

转载自www.cnblogs.com/chengjianxiaoxue/p/10145100.html