Arjit Chaudhary
Arjit Chaudhary

Reputation: 31

How can I use AWK to remove "name" columns and only print the kvm* fields?

I need a bit of help parsing a list. I've got it till the "name" column but need to take it a bit further and drop off the "Name" tag and keep only the list (i.e. kvm670...kvm673). For example:

[root@la04 net]#  virsh list | awk '{print $2}''
Name

kvm670
kvm671
kvm672
kvm673

How can I print only the kvm* fields?

Upvotes: 0

Views: 252

Answers (1)

Todd A. Jacobs
Todd A. Jacobs

Reputation: 84443

Use a pattern to only print lines of interest. For example:

virsh list | awk '/kvm[[:digit:]]+/ {print $2}'

Upvotes: 2

Related Questions