Chinaunix

标题: 用awk怎样实现这个小功能? [打印本页]

作者: pengxihan    时间: 2008-12-18 15:38
标题: 用awk怎样实现这个小功能?
比如一个文本中有这样一行:
This is a test, A=7, B=8
怎样用awk解析出A的值?
或者不用awk也可以。
作者: ly5066113    时间: 2008-12-18 15:42
echo 'This is a test, A=7, B=8' | awk -F '[=,]' '{print $3}'
作者: biglazybug    时间: 2008-12-18 15:45
echo "This is a test, A=7, B=8" | sed -r 's/.*A=([0-9]).*/\1/'
作者: welcome008    时间: 2008-12-18 17:46
cut -d"=" -f2 filename|cut -d"," -f1
作者: ILoveMK    时间: 2008-12-18 18:26
提示: 作者被禁止或删除 内容自动屏蔽
作者: blackold    时间: 2008-12-18 18:27
cut, awk, sed, etc.
作者: cjaizss    时间: 2008-12-19 10:40
原帖由 ly5066113 于 2008-12-18 15:42 发表
echo 'This is a test, A=7, B=8' | awk -F '[=,]' '{print $3}'

这种写法,这个......
作者: 我是DBA    时间: 2008-12-19 10:44
原帖由 ly5066113 于 2008-12-18 15:42 发表
echo 'This is a test, A=7, B=8' | awk -F '[=,]' '{print $3}'

这样,。行。。。
作者: pengxihan    时间: 2008-12-19 11:59
都行,但还是觉得cut简单明了,谢谢各位了!




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