0

I am trying to see whats the best way to extract the 3rd line from this command but i can't seem to get it

awk 'BEGIN{while("service ipsec status" | getline x) print  x}'
fedorqui
  • 275,237
  • 103
  • 548
  • 598
Luis
  • 83
  • 2
  • 10
  • awk is a tool for parsing text, it is not an environment from which to call external tools. That would be a shell. Using getline is rarely the right approach, see http://awk.info/?tip/getline. – Ed Morton Jul 29 '13 at 14:29
  • 2
    fedorqui: `awk 'NR==3{print}'` you mean? – Vovanium Jul 29 '13 at 14:29

2 Answers2

2
service ipsec status | awk 'NR==3'
Ed Morton
  • 188,023
  • 17
  • 78
  • 185
0

Using sed:

service ipsec status | sed '3!d'
devnull
  • 118,548
  • 33
  • 236
  • 227