Print the previous line

My requirement is that when ever search criteria matchs in log file, the previous line just above the search word as well as search word should be print.

sample log file

--03-19T11:26  xxx    create version "a.sh@@/main/6"
  "104157 "
--03-18T16:01  xxx    create version "a.sh@@/main/5"
  "104157 "
--03-16T12:51  xxx    create version "a.sh@@/main/4"
  "874569"
--03-09T17:49  xxx    create version "a.sh@@/main/3"
  "874569"
--02-23T07:21  xxx  create version b.sh@@/main/14
  "94145"
--02-22T07:12  xxx  create version "b.sh@@/main/13"
  "94145"
--02-21T00:10  xxx    create version "b.sh@@/main/12"
  "2010"
```[/i]


No if i search for 94145, then output shoul be \-
 
```text
--02-23T07:21  xxx  create version b.sh@@/main/14    <-- previous line   
  "94145"                                                              <-- search critria
--02-22T07:12  xxx  create version b.sh@@/main/13   <-- previous line   
  "94145"                                                  <-- search critria

another example, if user search for 2010, then output should be -[/i]

--02-21T00:10  xxx    create version "b.sh@@/main/12"
  "2010"

Any kind of help will be appriciated.

Thanks in advance.

awk '$0 ~ v { print p RS $0 }
{ p = $0 }' v=94145 infile

And of course, you may need to make the search more specific.

Thanks!!

Can you please tell me should i use your suggestion as a awk script or as a command ??

---------- Post updated at 06:20 PM ---------- Previous update was at 06:19 PM ----------

Can yopu please ellobrate it more??

Hi, Try this

grep -B1 "94145" testfile

Consider that -A/B are supported only by GNU grep.

---------- Post updated at 02:57 PM ---------- Previous update was at 02:56 PM ----------

Just run the script on the command line:

awk '$0 ~ v { print p RS $0 } { p = $0 }' v=94145 <your_log_file_name>

I tried what you said and got following error message

 
$ awk '$0 ~ v { print p RS $0 } { p = $0 }' v=94145 log
awk: syntax error near line 1
awk: bailing out near line 1
$ 

Please remember that i am using K shell and Sun Solaries as OS

OK, just use nawk instead of awk.