AWK / tail Issue

Hello,

I am using a tail command to fetch the line before last in a log file.

the two last lines are as followed:

11-01-16 11:55:45.174 | CClientObject::InitTraceLevelInCache Starting 
CClientObject::InitTraceLevelInCache End 

I am doing a awk statement to gather only the numeric values:

tmp_tail=`tail -2 "$trace" | awk '{print $1$2}' | cut -f,1 -d '.' | tr -d '-' | tr -d ':'`

output:

110116115545
CClientObjectInitTraceLevelInCacheEnd

I want only the output for the line before last --> i.e. 110116115545

Please assist.

As you seem to be having fun with pipes, what harm would another one do?

tmp_tail=$(tail -2 ...... | head -1)

Some sed (which I'm sure could be simplified):

$ sed -n '${g;s/\..*//;s/[^0-9]//g;p;};h' file
110116115545
2 Likes