0

My program output is as the following:

# myprogram list
val
val.dev
val.int
val.int.p1
val.int.p2
val.int.p3
val.int.p4
val.int.p5
val.dev.p6

I want to extract from the above output only strings under val.int. so I want to add something to the command in order to get the following output:

# myprogram list|<something options>
p1
p2
p3
p4
p5

Is it possible to do it with awk (or someting similar like sed) in only one call of awk?

4

4 回答 4

2
awk 'NF>2 {print $3}' FS=.
  • 将字段分隔符更改为.
  • 打印字段 3
于 2013-04-26T16:42:24.990 回答
2
myCommand | sed -n 's/val\.int\.//p'
于 2013-04-26T16:44:37.617 回答
1

还有另一种解决方案,这个涉及grepPerl 正则表达式:

$ myprogram list | grep -Po "(?<=val\.int\.).*"
于 2013-04-26T18:05:53.030 回答
1

尝试这个:

awk -F'val.int.' '$0=$2' file

文件包含您的数据:

kent$ awk -F'val.int.' '$0=$2' file
p1
p2
p3
p4
p5
于 2013-04-26T16:43:16.753 回答