Extract string from output command

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?

Upvotes: 0

Views: 1024

Answers (4)

Kent
Kent

Reputation: 195229

try this:

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

file contains your data:

kent$ awk -F'val.int.' '$0=$2' file
p1
p2
p3
p4
p5

Upvotes: 1

Zombo
Zombo

Reputation: 1

awk 'NF>2 {print $3}' FS=.
  • change field separator to .
  • print field 3

Upvotes: 2

chepner
chepner

Reputation: 532238

Yet another solution, this one involving grep and Perl regular expressions:

$ myprogram list | grep -Po "(?<=val\.int\.).*"

Upvotes: 1

tstone2077
tstone2077

Reputation: 514

myCommand | sed -n 's/val\.int\.//p'

Upvotes: 2

Related Questions