Easy AWK question

Ive got some output in a file that looks exactly like this:

1
-----------
1542

1 record(s) selected.

How do I just extract that 1542 and drop it into another file or (preferrably) a variable (using a ksh script)

 awk '{ if( $0 !~ /[0-9]{4}/) {continue} 
          print $0; exit }' filename

I need to clarify something...I think your script is going to extract exactly 4 digits....there is a chance the number could be 1,2,3,4 or 5 digits long...will this still work?

How is this since you're parsing sqlplus output, key off of the column heading dashes:

VARIABLE=`nawk '/-----------/ {getline ; print}' filename`

Why not do this (tmarikle is right) in your sql:

set pages 0
spool t.lis
select ...................;
spool off

Now t.lis has exactly one line with just one number.

Well the problem is that I get leading spaces before the number...My original solution was to use SED to delete the first 3 and last 3 lines...but I still have the leading spaces..

Read my previous post. The solution omitted the filename.

For what it's worth, Jim's point is correct, and removing leading spaces is simple and precise. For example, if you have a variable VAR that contains leading spaces such as vAR=" 123", you can remove those using built-in functionality in KSH and BASH (e.g. echo "${VAR##+([ ])" ).

I couldnt get mcnamara's to work, but your worked fine...thanks!

You could remove leading spaces back down to sqlplus using ... to_char( thenumberhere,'fm0000000' ) ...

awk 'BEGIN{RS=""} {print $NF; exit}'