Format LOG File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Format LOG File
# 1  
Old 07-08-2011
Format LOG File

Hello,

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

Here is what I am getting :

Code:
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

Code:
/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 ; ))
# 2  
Old 07-08-2011
You can do somthing like thar :
Code:
awk '
    /\// {
        for (field=7; field<=NF; field++) {
            if (substr($field,1,1) == "/") {
                print $6,$field,$(field+1);
                break;
            }
        }
    }
' inputfile

Jean-Pierre.
# 3  
Old 07-08-2011
Code:
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.
# 4  
Old 07-08-2011
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 :

Code:
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 ...

Last edited by Aswex; 07-08-2011 at 10:58 AM.. Reason: For CTSGNB - ERROR
# 5  
Old 07-08-2011
Of course you can just put the code in several lines if you prefer (it is just a cosmetic matter).
Code:
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.
# 6  
Old 07-08-2011
Code:
awk  -F'OPERATIONNEL' '/OPERATIONNEL/{print "/OPERATIONNEL"$2}' inputfile


Last edited by Franklin52; 07-09-2011 at 09:14 AM.. Reason: Code tags
# 7  
Old 07-08-2011
Quote:
Originally Posted by ltomuno
awk -F'OPERATIONNEL' '/OPERATIONNEL/{print "/OPERATIONNEL"$2}' inputfile
You miss the insertion of $6 after the /OPERATIONNEL/.... string
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Format a log file using sed

I am looking to extract something like this from the below sample log file. 10.28.76.15 SSLC=Z42 71.19.175.130 10.28.76.15 SSLC=Z42 71.19.175.130 10.28.76.15 SSLC=Z42 71.19.175.130 for that I tried something like below and I have no clue how to extract the IP address marked red in the log... (6 Replies)
Discussion started by: Tuxidow
6 Replies

2. Shell Programming and Scripting

format log file

Hello, I am on solaris here is what I have *****LIST OF ATTRIBUTS FROM FILES***** FILE='/N1B/2002/05/ACL1B_2002_05_01_B_00.TAR ... (5 Replies)
Discussion started by: Aswex
5 Replies

3. Shell Programming and Scripting

Format log file - SED

Hello, I need help to format a log file...again ; )) Here is what I have : FILE='/OPERATIONNEL/SATURNE/MASTER/SATURNE_MASTER_PRE_R20110119.TAR.GZ ... (5 Replies)
Discussion started by: Aswex
5 Replies

4. Shell Programming and Scripting

Format log file

Hello, I need help to format log file. I am looking for the most short way to to it here is what I have : /data_val/SATURNE/MASTER/PRE/SATURNE_1dAV_20110301_20110302_T3D_T_FCST_R20110216.nc 3581376 here is what I need : SATURNE_1dAV_20110301_20110302_T3D_T_FCST_R20110216.nc 3581376... (8 Replies)
Discussion started by: Aswex
8 Replies

5. Shell Programming and Scripting

Log File - Format

Dear all, I need help to format a log file : Here is the output (Go to the end of the Wrap Code to see caracter at the end of line): FILE='/OPERATIONNEL/SATURNE/PHYS_MOD/NOWMOD/SATURNE_1DAV_20110201_20110202_ICEMOD_R20110202.NC ... (5 Replies)
Discussion started by: Aswex
5 Replies

6. UNIX for Dummies Questions & Answers

Log file format!

DO log files have 1 universal format. And if any body know how to depict the $1 to $10 arguments of this file. (4 Replies)
Discussion started by: nixhead
4 Replies

7. UNIX for Dummies Questions & Answers

Format log file

Hi, I need help to format log file that look like this : FILE='/BD_TOTO/MMX_RNX/MMX_RNX_2009_282_0001.TGZ ';; SIZE(Ko)='32528 ' ARC_DATE='2009-10-13' ;;... (6 Replies)
Discussion started by: Aswex
6 Replies

8. Shell Programming and Scripting

SED - log file format

Hello everyone, I have a log file : \data\file\script\command_0001 \data\file\script\command_0002 \data\file\script\command_0003 I need to make all lines on this way \data\file\script\command_0001 \data\file\script\command_0002 \data\file\script\command_0003 I know this could be done... (11 Replies)
Discussion started by: Aswex
11 Replies

9. Shell Programming and Scripting

convert date format to mysql date format in log file

I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column. I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this? Sample input 02/27/09,23:52:31 02/27/09,23:52:52... (3 Replies)
Discussion started by: hazno
3 Replies

10. UNIX for Advanced & Expert Users

Correct format in a log file

I'm trying to read the output of a .sql script (simple insert and commit oracle pl/slq script) to a log file using a shell script. My problem is I end up with a log file that looks like this: sd12@phenix97:/detain/sd12/logs > cat 20071205_detain_20071206.log 12320496 rows created. Commit... (11 Replies)
Discussion started by: sd12
11 Replies
Login or Register to Ask a Question