当前位置: 技术问答>linux和unix
从一段数据中提取某列,并比较?(有具体数据)
来源: 互联网 发布时间:2016-05-04
本文导语: 下面是一段数据,我想从中选择需要的数据,请高手... ***标题张三*** Filesystem 1024-blocks Used Available Capacity Mounted on /dev/sda3 20161204 9825400 9311664 52% /home Filesystem...
下面是一段数据,我想从中选择需要的数据,请高手...
***标题张三***
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sda3 20161204 9825400 9311664 52% /home
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sda2 60476068 9452468 47951572 17% /opt
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sde2 20651028 12332880 7269104 63% /jh_arch
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sde3 20619668 6182856 13389376 32% /esb_arch
***标题李四***
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sda3 20161204 9825400 9311664 88% /home
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sda2 60476068 9452468 47951572 42% /opt
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sde2 20651028 12332880 7269104 90% /jh_arch
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sde3 20619668 6182856 13389376 36% /esb_arch
--------
希望得到的结果
1 从中选出 >50% 的行 (基本问题)
/dev/sda3 20161204 9825400 9311664 52% /home
/dev/sde2 20651028 12332880 7269104 63% /jh_arch
/dev/sda3 20161204 9825400 9311664 88% /home
/dev/sde2 20651028 12332880 7269104 90% /jh_arch
2 希望标题也能显示出来 (如果有更好)
***标题张三***
/dev/sda3 20161204 9825400 9311664 52% /home
/dev/sde2 20651028 12332880 7269104 63% /jh_arch
***标题李四***
/dev/sda3 20161204 9825400 9311664 88% /home
/dev/sde2 20651028 12332880 7269104 90% /jh_arch
***标题张三***
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sda3 20161204 9825400 9311664 52% /home
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sda2 60476068 9452468 47951572 17% /opt
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sde2 20651028 12332880 7269104 63% /jh_arch
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sde3 20619668 6182856 13389376 32% /esb_arch
***标题李四***
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sda3 20161204 9825400 9311664 88% /home
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sda2 60476068 9452468 47951572 42% /opt
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sde2 20651028 12332880 7269104 90% /jh_arch
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sde3 20619668 6182856 13389376 36% /esb_arch
--------
希望得到的结果
1 从中选出 >50% 的行 (基本问题)
/dev/sda3 20161204 9825400 9311664 52% /home
/dev/sde2 20651028 12332880 7269104 63% /jh_arch
/dev/sda3 20161204 9825400 9311664 88% /home
/dev/sde2 20651028 12332880 7269104 90% /jh_arch
2 希望标题也能显示出来 (如果有更好)
***标题张三***
/dev/sda3 20161204 9825400 9311664 52% /home
/dev/sde2 20651028 12332880 7269104 63% /jh_arch
***标题李四***
/dev/sda3 20161204 9825400 9311664 88% /home
/dev/sde2 20651028 12332880 7269104 90% /jh_arch
|
awk '{if(NF==1)printf $0 "n";if((NF==6)&& ($5>50))printf $0 "n"}' test.txt
|
这个用 bash 自带的 awk脚本 写是最方便不过的了
awk '{ if($5>50) print $0; }' file.txt
我只是给个雏形 要考虑 $5 是 XX%格式的,用awk自带的字符串处理函数 提取出那个数字,再与50比较就OK了。
awk '{ if($5>50) print $0; }' file.txt
我只是给个雏形 要考虑 $5 是 XX%格式的,用awk自带的字符串处理函数 提取出那个数字,再与50比较就OK了。