Need to build a grep/sed/awk filter

Hi
I need to to direct only the path and the name of the trace file to a new file. How do I use grep/awk/sed filter?
eg.

 
ABC.root>cat alert_omc_dg.log | grep trc
ORA-00060: Deadlock detected. More info in file /u01/oradata/omc/udump/omc_dg_ora_3555.trc.
ORA-00060: Deadlock detected. More info in file /u01/oradata/omc/udump/omc_dg_ora_26570.trc.
ORA-00060: Deadlock detected. More info in file /u01/oradata/omc/udump/omc_dg_ora_13896.trc.
Errors in file /u01/oradata/omc/udump/omc_dg_ora_24462.trc:
ORA-00060: Deadlock detected. More info in file /u01/oradata/omc/udump/omc_dg_ora_565.trc.
ORA-00060: Deadlock detected. More info in file /u01/oradata/omc/udump/omc_dg_ora_20888.trc.

output file should have contents like as follows:

 
/u01/oradata/omc/udump/omc_dg_ora_3555.trc
..
..
..
/u01/oradata/omc/udump/omc_dg_ora_565.trc
/u01/oradata/omc/udump/omc_dg_ora_20888.trc

The think is here the columns are not fixed in the error lines hence I cannot use cut etc.
Please suggest a way out. Thank you.

About to go into a meeting, so I don't have time to test,
but I think this get's it done with sed. HTH

sed -ne 's/.*file.\(.*\.trc\)/\1/p' >newfile

Warning, untested:

awk '/trc.$/{print $NF}'

Should work as long as you don't introduce whitespaces in the file name, or the filename suddenly isn't in the last column anymore.

Yup it works mostly, just adding the input file and removing the trailing dot and colon from the output, as well the -ne and p:

sed 's/.*file.\(.*\.trc\)/\1/' infile > newfile

Thank you Zaxxon,
I tried

sed 's/.*file.\(.*\.trc\)/\1/' alert_omc_dg.log > newfile.txt

But the newfile.txt has all the details of alert_omc_dg.log.

Thanks Pludi,
It worked but it has . and : towards the end.
I tried eliminating . by using cut filter

ABC:root>cat alert_omc_dg.log | awk '/trc.$/{print $NF}' | cut -d. -f1,2
/u01/oradata/omc/udump/omc_dg_ora_3555.trc
/u01/oradata/omc/udump/omc_dg_ora_26570.trc
/u01/oradata/omc/udump/omc_dg_ora_13896.trc
/u01/oradata/omc/udump/omc_dg_ora_24462.trc:
/u01/oradata/omc/udump/omc_dg_ora_565.trc
/u01/oradata/omc/udump/omc_dg_ora_20888.trc

but : remains on the 4th line :frowning:

Oh I missed adding a .* after the group:

$> cat infile
ORA-00060: Deadlock detected. More info in file /u01/oradata/omc/udump/omc_dg_ora_3555.trc.
ORA-00060: Deadlock detected. More info in file /u01/oradata/omc/udump/omc_dg_ora_26570.trc.
ORA-00060: Deadlock detected. More info in file /u01/oradata/omc/udump/omc_dg_ora_13896.trc.
Errors in file /u01/oradata/omc/udump/omc_dg_ora_24462.trc:
ORA-00060: Deadlock detected. More info in file /u01/oradata/omc/udump/omc_dg_ora_565.trc.
ORA-00060: Deadlock detected. More info in file /u01/oradata/omc/udump/omc_dg_ora_20888.trc.
$> sed 's/.*file.\(.*\.trc\).*/\1/' infile > newfile
/u01/oradata/omc/udump/omc_dg_ora_3555.trc
/u01/oradata/omc/udump/omc_dg_ora_26570.trc
/u01/oradata/omc/udump/omc_dg_ora_13896.trc
/u01/oradata/omc/udump/omc_dg_ora_24462.trc
/u01/oradata/omc/udump/omc_dg_ora_565.trc
/u01/oradata/omc/udump/omc_dg_ora_20888.trc

Works with GNU sed and awk on AIX.

---------- Post updated at 05:13 PM ---------- Previous update was at 05:11 PM ----------

For Pludi's awk you can do this so you don't need to pipe into cut:

awk '/trc.$/{sub(/.$/,"",$NF); print $NF}' infile
/u01/oradata/omc/udump/omc_dg_ora_3555.trc
/u01/oradata/omc/udump/omc_dg_ora_26570.trc
/u01/oradata/omc/udump/omc_dg_ora_13896.trc
/u01/oradata/omc/udump/omc_dg_ora_24462.trc
/u01/oradata/omc/udump/omc_dg_ora_565.trc
/u01/oradata/omc/udump/omc_dg_ora_20888.trc

Bingo !!! it works.. Thank you very much... I'll explore how the filter works.. new to Unix filters but am loving it... :slight_smile:

Thanks zaxxon, completely missed that one. Shouldn't code when low on caffeine...

Thanks from me too Zaxxon. I use '-e' quite a bit, because I usually have more than one pattern to find, but that's not the OP's requirements. Good catch on the trailing '.' and ':' and a big "D'oh!" from me for forgetting the input file! :wink:

The '-n' and 'p' though I felt were needed since the OP was going through an oracle alert log, which usually contain lines other than those the OP "grep'ed" out of them.

So in order to simply process the whole alertlog and not have to pre "grep" it I figured I'd toss in the '-n' to hold off printing and the 'p' to print only that which fit the pattern to the newfile.

Unfortunately in my rush I didn't state what I was hoping to perform.