Print lines before after pattern meacted

Hi All,

Am trying to print pervious lines of the pattern matched, I was able to print pattern matched and the required data but don't know how to get the pervious line.

 ifconfig -a | grep  10.118.67.33 | sed -e 's/^[[: :]]*//' -e 's/[[: :]]*$//' | awk '{FS=" "; print $6}'

output I get is the ipaddress ie,

 10.118.67.33
 

what am looking is how to get the pervious line of this ipaddress... can someone please help me on this.

Many thanks
Ops

The whole line before pattern?

ifconfig -a | awk '{a[++i]=$0;} /10.118.67.33/{print a[NR-1]}'
1 Like

Thanks Aia. logic works perfectly. this what I was looking for and I was struggling to get pervious whole line.

Many Thank Again.