免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6705 | 回复: 5
打印 上一主题 下一主题

求助: shell 如何grep 得到下一行的数值 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-14 08:27 |只看该作者 |倒序浏览
#bdf
Filesystem          kbytes    used   avail %used Mounted on
/dev/vg00/lvol3    1048576  419736  623936   40% /
/dev/vg00/lvol1     511672   41512  418992    9% /stand
/dev/vg00/lvol8    5242880  994512 4215832   19% /var
/dev/vg00/lvol7    3145728 1278664 1852488   41% /usr
/dev/vg00/lvol4    2097152 1327048  764288   63% /tmp
/dev/vg00/lvol6    5242880 1834168 3382144   35% /opt
/dev/vg00/lvol5    2097152  166176 1915944    8% /home
/dev/vg00/lvol9    21037056 2492536 18255320   12% /app
bilud01:/backup/software/media
                   157261824 44812008 111571792   29% /backup145



想取出 used 的数据,如何一条命令实现?

格式如
/dev/vg00/lvol3   40% /
/dev/vg00/lvol1     9% /stand
/dev/vg00/lvol8     19% /var
/dev/vg00/lvol7    41% /usr
/dev/vg00/lvol4    63% /tmp
/dev/vg00/lvol6    35% /opt
/dev/vg00/lvol5    8% /home
/dev/vg00/lvol9    12% /app
bilud01:/backup/software/media 29% /backup145

[ 本帖最后由 wazhl 于 2008-6-14 08:29 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-06-14 10:46 |只看该作者
bdf | awk 'NR>1{print $1,$5,$6}'

论坛徽章:
11
金牛座
日期:2015-03-19 16:56:22数据库技术版块每日发帖之星
日期:2016-08-02 06:20:00数据库技术版块每日发帖之星
日期:2016-04-24 06:20:00数据库技术版块每日发帖之星
日期:2016-04-13 06:20:00IT运维版块每日发帖之星
日期:2016-04-13 06:20:00数据库技术版块每日发帖之星
日期:2016-02-03 06:20:00数据库技术版块每日发帖之星
日期:2015-08-06 06:20:00季节之章:春
日期:2015-03-27 15:54:57羊年新春福章
日期:2015-03-27 15:54:37戌狗
日期:2015-03-19 16:56:41数据库技术版块每日发帖之星
日期:2016-08-18 06:20:00
3 [报告]
发表于 2008-06-14 11:47 |只看该作者

回复 #2 liyong_nb 的帖子

要注意的是最后一行~~这个以前讨论过的~~

论坛徽章:
0
4 [报告]
发表于 2008-06-14 12:42 |只看该作者
awk 'NR>1{if(NF==1){printf("%s ",$1);getline;print $(NF-1),$NF}else{print $1,$(NF-1),$NF}}'

论坛徽章:
11
金牛座
日期:2015-03-19 16:56:22数据库技术版块每日发帖之星
日期:2016-08-02 06:20:00数据库技术版块每日发帖之星
日期:2016-04-24 06:20:00数据库技术版块每日发帖之星
日期:2016-04-13 06:20:00IT运维版块每日发帖之星
日期:2016-04-13 06:20:00数据库技术版块每日发帖之星
日期:2016-02-03 06:20:00数据库技术版块每日发帖之星
日期:2015-08-06 06:20:00季节之章:春
日期:2015-03-27 15:54:57羊年新春福章
日期:2015-03-27 15:54:37戌狗
日期:2015-03-19 16:56:41数据库技术版块每日发帖之星
日期:2016-08-18 06:20:00
5 [报告]
发表于 2008-06-16 09:42 |只看该作者
原帖由 vincentn 于 2008-6-14 12:42 发表
awk 'NR>1{if(NF==1){printf("%s ",$1);getline;print $(NF-1),$NF}else{print $1,$(NF-1),$NF}}'

差不多的,修改下.
  1. bdf | awk 'NR>1{if(NF<6){f1=$1;getline;print f1,$(NF-1),$NF}else{print $1,$(NF-1),$NF}}'
复制代码

论坛徽章:
0
6 [报告]
发表于 2008-06-16 10:55 |只看该作者
如果LZ一定要grep的话可以看一下-A -B -C参数,-A是后面,-B是前面,-C是前后都要。
       -A NUM, --after-context=NUM
              Print  NUM  lines  of trailing context after matching lines.  Places a line containing a group
              separator (--) between contiguous groups of matches.  With the -o or  --only-matching  option,
              this has no effect and a warning is given.

       -B NUM, --before-context=NUM
              Print  NUM  lines  of leading context before matching lines.  Places a line containing a group
              separator (--) between contiguous groups of matches.  With the -o or  --only-matching  option,
              this has no effect and a warning is given.

       -C NUM, -NUM, --context=NUM
              Print  NUM  lines  of output context.  Places a line containing a group separator (--) between
              contiguous groups of matches.  With the -o or --only-matching option, this has no effect and a
              warning is given.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP