0

I have output like so

v12:     "owner" : "cs1372",
v12:     "num-of-connections" : 1,
v12:     "owner" : "cq5838",
v5:     "owner" : "bb9886",
v5:     "owner" : "aq0903",
v5:     "owner" : "bj2468",
v5:     "owner" : "di3080",
v5:     "num-of-connections" : 1,

I need to return the line above the num-of-connections line. So what I want in this output is

v12:     "owner" : "cs1372",
v5:     "owner" : "di3080",

Is there an easy way to do this with sed or awk?

0

1 Answer 1

1

Using awk:

$ awk '$2=="\"num-of-connections\""{ print prev } { prev=$0 }' file
v12:     "owner" : "cs1372",
v5:     "owner" : "di3080",

Save the current record in variable prev. If the second field equals "num-of-connections", print variable prev.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.