Question: I want to use awk for printing a match of some pattern, only if it is the last line of the file before some constant text.

For example, i want to print the value of "c" only if it is the last line before some constant text:

```
cat file.txt:
a=1
b=2
c=3
...constant text...

```

print 3.

```
cat file.txt:
a=1
c=3
b=2
...constant text...

```

do not print anything.

How do I do that..? How can awk know if it's the last number of the file?

Answer: 
If you don't mind using grep it has an option to print lines before match.

Option is : -B num, --before-context=num

In your case :

```
cat file.txt|grep -B 1 "constant text"|grep "c="|cut -f2 -d'='

```

Explanation :

1. Print just the line before constant text.
2. Filter all c values from output.
3. Extract second field with '=' delimiter.
Some googling found me the best answer so far, though I already got an answer: Using `tac` makes it much simpler...

`tac file | awk 'NR==2{if ( $1=="c") print $2}'`

The line number is one after the "constant text". If the "constant text" is one line - `NR==2`. If it is two lines - `NR==3`. Haven't decided yet what format the constant text should be...