Format LOG File

Hello,

I just need help to format log file that contain huge amont of lines:

Here is what I am getting :

STAS022  RC = 0 I Suppression de /OPERATIONNEL/SATURNE/PGN/HD/SATURNE_1DAV_20100415_20110415_ISI_R20110430.NC effectuee
STAS034  RC = 0 I Deroulement correct
STAF067  RC = 9 E Fichier /OPERATIONNEL/SATURNE/PGN/HD/SATURNE_1DAV_20100430_20110430_ISI_R20110430.NC inexistant ou droit insuffisant
STAS035  RC = 9 W Liste traitee partiellement

Here is what I need to keep

/OPERATIONNEL/SATURNE/PGN/HD/SATURNE_1DAV_20100415_20110415_ISI_R20110430.NC Suppression effectuee
/OPERATIONNEL/SATURNE/PGN/HD/SATURNE_1DAV_20100430_20110430_ISI_R20110430.NC Fichier inexistant

Tanks a lot for your help ; ))

You can do somthing like thar :

awk '
    /\// {
        for (field=7; field<=NF; field++) {
            if (substr($field,1,1) == "/") {
                print $6,$field,$(field+1);
                break;
            }
        }
    }
' inputfile

Jean-Pierre.

awk '/Suppression|Fichier/{for(i=0;++i<=NF;) if($i~/^\//) print ($(i-2)~/Suppression/)?$i" "$(i-2)" "$(i+1):($(i-1)~/Fichier/)?$i" "$(i-1)" "$(i+1):z}' inputfile

use nawk or /usr/xpg4/bin/awk if running on SunOS/Solaris plateform

---------- Post updated at 03:12 PM ---------- Previous update was at 03:07 PM ----------

@aigles,

I tested your code, your results gets some remaining "Suppression" and "Fichier" unexpected (according to the specifications) occurrence before the /OP* strings.

Dear Jean-Pierre,

Your are always a good help for me ... Thanks. Your code is almost good but here is there result I am getting :

Fichier /OPERATIONNEL/SATURNE/PGN/HD/SATURNE_1DAV_20100415_20110415_ISI_R20110430.NC Suppression effectuee
Fichier/OPERATIONNEL/SATURNE/PGN/HD/SATURNE_1DAV_20100430_20110430_ISI_R20110430.NC Fichier inexistant

Is there a way to do not keep "Fichier" in your code ?

I will insert your code on a shel script so it will be better for me to do not insert a one line code ..

Thanks ctsgnb, I will try your code ...

Dear CSTNGB,

your line code work as expected .... Thanks a lot, but , do you thinks it's possible to send it again in shell script way instead of one line code ? If not don't worry, I will keep it in this way.

Anyway thnaks a lot for your help ; )

In fact I was testing on files that were not existing and the code was working fine, but the log file may have some file existing ans some other not, but the line code works only if the statut of the file is "Fichier inexistant"

I am lost ...

Of course you can just put the code in several lines if you prefer (it is just a cosmetic matter).

awk '/Suppression|Fichier/{
    for(i=0;++i<=NF;) 
        if($i~/^\//) 
            print ($(i-2)~/Suppression/)?$i" "$(i-2)" "$(i+1):($(i-1)~/Fichier/)?$i" "$(i-1)" "$(i+1):z
}' inputfile

If you want the code to work for a more generic input, then please just provide a more representative example of input you have and output you expect.

awk  -F'OPERATIONNEL' '/OPERATIONNEL/{print "/OPERATIONNEL"$2}' inputfile

You miss the insertion of $6 after the /OPERATIONNEL/.... string

awk '
    /\// {
        for (field=7; field<=NF; field++) {
            if (substr($field,1,1) == "/") {
                print $field,$6,$(field+1);
                break;
            }
        }
    }
' inputfile

or

awk '/\// { for (field=7; field<=NF; field++) { if (substr($field,1,1) == "/") { print $field,$6,$(field+1); break } } } ' inputfile

Jean-Pierre.