Chinaunix

标题: 文本处理,6个数有一个大于577则输出 [打印本页]

作者: blueghost_mt    时间: 2013-08-15 15:18
标题: 文本处理,6个数有一个大于577则输出
本帖最后由 blueghost_mt 于 2013-08-15 15:25 编辑

RELEASE PET INFO[UserId=54 PetId=23 Name=怪物1 P1= P2= Lv=1 Gen=1 Gender=1 Char=3 Flash=0 IV=5 14 32 1 8 28 EV=889 0 0 0 609 0 Height=218 Weight=752 Frd=0 Spell=39 66 96 91 Feature=0 0 Exp=0 Birth=1369020924 BodySize=109 OtherSpell=0 0 0 0 SpellStatus=0 0 0 0BeObjId=15 BePetId=23 ExpAdd=0 ]
RELEASE PET INFO[UserId=54 PetId=23 Name=怪物21 P1= P2= Lv=1 Gen=1 Gender=1 Char=3 Flash=0 IV=5 14 32 1 8 28 EV=0 0 0 0 0 0 Height=218 Weight=752 Frd=0 Spell=39 66 96 91 Feature=0 0 Exp=0 Birth=1369020924 BodySize=109 OtherSpell=0 0 0 0 SpellStatus=0 0 0 0BeObjId=15 BePetId=23 ExpAdd=0 ]
RELEASE PET INFO[UserId=54 PetId=23 Name=怪物132 P1= P2= Lv=1 Gen=1 Gender=1 Char=3 Flash=0 IV=5 14 32 1 8 28 EV=0 0 32 0 0 0 Height=218 Weight=752 Frd=0 Spell=39 66 96 91 Feature=0 0 Exp=0 Birth=1369020924 BodySize=109 OtherSpell=0 0 0 0 SpellStatus=0 0 0 0BeObjId=15 BePetId=23 ExpAdd=0 ]
RELEASE PET INFO[UserId=54 PetId=23 Name=怪物21 P1= P2= Lv=1 Gen=1 Gender=1 Char=3 Flash=0 IV=5 14 32 1 8 28 EV=0 0 0 0 77 0 Height=218 Weight=752 Frd=0 Spell=39 66 96 91 Feature=0 0 Exp=0 Birth=1369020924 BodySize=109 OtherSpell=0 0 0 0 SpellStatus=0 0 0 0BeObjId=15 BePetId=23 ExpAdd=0 ]
RELEASE PET INFO[UserId=54 PetId=23 Name=怪物98 P1= P2= Lv=1 Gen=1 Gender=1 Char=3 Flash=0 IV=5 14 32 1 8 28 EV=0 578 0 0 33 0 Height=218 Weight=752 Frd=0 Spell=39 66 96 91 Feature=0 0 Exp=0 Birth=1369020924 BodySize=109 OtherSpell=0 0 0 0 SpellStatus=0 0 0 0BeObjId=15 BePetId=23 ExpAdd=0 ]

这样的一堆数据,如果我要提取出EV后面的6个数字里任何一个数字有大于577的行改如何处理?
期望结果提取出来的
RELEASE PET INFO[UserId=54 PetId=23 Name=怪物1 P1= P2= Lv=1 Gen=1 Gender=1 Char=3 Flash=0 IV=5 14 32 1 8 28 EV=889 0 0 0 609 0 Height=218 Weight=752 Frd=0 Spell=39 66 96 91 Feature=0 0 Exp=0 Birth=1369020924 BodySize=109 OtherSpell=0 0 0 0 SpellStatus=0 0 0 0BeObjId=15 BePetId=23 ExpAdd=0 ]
RELEASE PET INFO[UserId=54 PetId=23 Name=怪物98  P1= P2= Lv=1 Gen=1 Gender=1 Char=3 Flash=0 IV=5 14 32 1 8 28 EV=0 578 0 0 33 0 Height=218 Weight=752 Frd=0 Spell=39 66 96 91 Feature=0 0 Exp=0 Birth=1369020924 BodySize=109 OtherSpell=0 0 0 0 SpellStatus=0 0 0 0BeObjId=15 BePetId=23 ExpAdd=0 ]
在此先行谢过各位大神了!
作者: yinyuemi    时间: 2013-08-15 15:35
回复 1# blueghost_mt
  1. awk -F'(EV=| Height)' '{for(i=1;i<=split($2,b," ");i++)if(b[i]>577){print;break}}'
复制代码

作者: jason680    时间: 2013-08-15 15:36
回复 1# blueghost_mt

Here you are

# awk -F"[ =]" '{for(n=0;n++<NF;)if($n~/^EV$/){for(c=0;c++<6;){t=n+c;if($t>577){print;next}}next}}' FILE
RELEASE PET INFO[UserId=54 PetId=23 Name=美美蛇 P1= P2= Lv=1 Gen=1 Gender=1 Char=3 Flash=0 IV=5 14 32 1 8 28 EV=889 0 0 0 609 0 Height=218 Weight=752 Frd=0 Spell=39 66 96 91 Feature=0 0 Exp=0 Birth=1369020924 BodySize=109 OtherSpell=0 0 0 0 SpellStatus=0 0 0 0BeObjId=15 BePetId=23 ExpAdd=0 ]
RELEASE PET INFO[UserId=54 PetId=23 Name=美美蛇 P1= P2= Lv=1 Gen=1 Gender=1 Char=3 Flash=0 IV=5 14 32 1 8 28 EV=0 578 0 0 33 0 Height=218 Weight=752 Frd=0 Spell=39 66 96 91 Feature=0 0 Exp=0 Birth=1369020924 BodySize=109 OtherSpell=0 0 0 0 SpellStatus=0 0 0 0BeObjId=15 BePetId=23 ExpAdd=0 ]

作者: blueghost_mt    时间: 2013-08-15 15:49
回复 3# jason680


    谢谢,能稍微讲下if($n~/^EV$/)是什么含义么?
作者: 关阴月飞    时间: 2013-08-15 15:59
回复 4# blueghost_mt

   判断 $n 的值是否等于 “EV”
   
作者: blueghost_mt    时间: 2013-08-15 16:27
回复 5# 关阴月飞


    哦~懂了~再问下,-F应该是指定分隔符吧"[ =]"代表什么含义?匹配等号之前的?
作者: 关阴月飞    时间: 2013-08-15 16:31
回复 6# blueghost_mt


     -F "[ =]"    以 “空格” 或 “=” 为分隔符
作者: blueghost_mt    时间: 2013-08-15 16:36
回复 7# 关阴月飞


    多谢了~~~明白了~
作者: jason680    时间: 2013-08-15 16:41
本帖最后由 jason680 于 2013-08-15 16:53 编辑

回复 6# blueghost_mt


IV=5 14 32 1 8 28 EV=889 0 0 0 609 0 Height=218

split key will be = (equal) or (white space)

and awk command will be

awk -F"[ =]" ...

the [ =] to tell awk to split the string by (white space) or = (equal) sign

作者: blueghost_mt    时间: 2013-08-15 17:24
回复 9# jason680


    虽然已经理解了,但还是谢谢你解释的那么清楚,感谢!
作者: rdcwayx    时间: 2013-08-16 08:13
回复 9# jason680

whitespace 不等于  blank space.
作者: jason680    时间: 2013-08-16 10:35
回复 11# rdcwayx

Thank you for your notice

http://en.wikipedia.org/wiki/Whitespace_%28computer_science%29
  In computer science, white space is any character or series of whitespace characters that represent horizontal or vertical space in typography. When rendered, a whitespace character does not correspond to a visible mark, but typically does occupy an area on a page. For example, the common whitespace symbol U+0020   space (HTML:  & #32; ), also ASCII 32, represents a blank space, used as a word divider in Western scripts.
...




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2