Log File - Format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Log File - Format
# 1  
Old 02-11-2011
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):

Code:
FILE='/OPERATIONNEL/SATURNE/PHYS_MOD/NOWMOD/SATURNE_1DAV_20110201_20110202_ICEMOD_R20110202.NC                                                                                                                                                             ';;
 ARC_DATE='2011-02-03'
 ARC_TIME='11.20.41'
;;

Here is the output needed :

Code:
/OPERATIONNEL/SATURNE/PHYS_MOD/NOWMOD/;SATURNE_1DAV_20110201_20110202_ICEMOD_R20110202.NC;2011-02-03

I am on solaris 9 (KSH)

I need this to export the log file to excel.

Thanks a lot for your help.

Here is I've done so far

Code:
nawk -F"'" '/FILE=/{gsub(" ","",$2);print $2}' infile

Output :

Code:
/OPERATIONNEL/SATURNE/PHYS_MOD/NOWMOD/SATURNE_1DAV_20110201_20110202_ICEMOD_R20110202.NC

But it's not good enought.

Last edited by Aswex; 02-11-2011 at 06:35 AM.. Reason: Here is what I've done so far :
# 2  
Old 02-11-2011
try..
Code:
awk -F\' '/FILE/{s=$2;getline;x=$2;print s";"x}' inputfile > outfile

# 3  
Old 02-11-2011
Dear michaelrozar17,

Thanks you so much for your quick reply. It's almost good but I am still in trouble as I need to get the date value on the same line. I don't know if you can see on the wrap code that the date value is end of line below the path file. Do you think it's possible to make it as I need ?

Code:
/OPERATIONNEL/SATURNE/PHYS_MOD/NOWMOD/SATURNE_1DAV_20110201_20110202_GRIDU_R20110202.NC                                                                                                                                                              ;2011-02-03
/OPERATIONNEL/SATURNE/PHYS_MOD/NOWMOD/SATURNE_1DAV_20110201_20110202_GRIDV_R20110202.NC                                                                                                                                                              ;2011-02-03
/OPERATIONNEL/SATURNE/PHYS_MOD/NOWMOD/SATURNE_1DAV_20110201_20110202_GRIDW_R20110202.NC                                                                                                                                                              ;2011-02-03
/OPERATIONNEL/SATURNE/PHYS_MOD/NOWMOD/SATURNE_1DAV_20110201_20110202_ICEMOD_R20110202.NC                                                                                                                                                             ;2011-02-03

Here is the output needed :

Code:
/OPERATIONNEL/SATURNE/PHYS_MOD/NOWMOD/;SATURNE_1DAV_20110201_20110202_GRIDU_R20110202.NC;2011-02-03
/OPERATIONNEL/SATURNE/PHYS_MOD/NOWMOD/;SATURNE_1DAV_20110201_20110202_GRIDV_R20110202.NC;2011-02-03
/OPERATIONNEL/SATURNE/PHYS_MOD/NOWMOD/;SATURNE_1DAV_20110201_20110202_GRIDW_R20110202.NC;2011-02-03
/OPERATIONNEL/SATURNE/PHYS_MOD/NOWMOD/;SATURNE_1DAV_20110201_20110202_ICEMOD_R20110202.NC;2011-02-03

# 4  
Old 02-11-2011
Use sed first to remove the extra spaces and save it in a file and then use awk.
Code:
sed '/FILE/s/ \+//' inputfile > outfile1
awk -F\' '/FILE/{s=$2;getline;x=$2;print s";"x}' outfile1 > outfile2

# 5  
Old 02-11-2011
Hi,

here is I've done :

Code:
nawk -F\' '/FILE/{s=$2;getline;x=$2;print s";"x}' | nawk '{ print $1 $2 }' infile

output result

Code:
/OPERATIONNEL/SATURNE/PHYS_MOD/NOWMOD/SATURNE_1DAV_20110201_20110202_GRIDU_R20110202.NC;2011-02-03
/OPERATIONNEL/SATURNE/PHYS_MOD/NOWMOD/SATURNE_1DAV_20110201_20110202_GRIDV_R20110202.NC;2011-02-03

But I still do not know how I could add a ";" on the front of the file name.

Thanks for your help.
# 6  
Old 02-11-2011
The output you posted has semi-colon in between..! However you could try as below
Code:
nawk -F\' '/FILE/{s=$2;getline;x=$2;print s";"x}' | nawk '{ print $1";"$2 }' infile

IMHO if the file is huge enough then invoking awk 2 times would be time consuming compared to the one time sed and awk. But it all depends on the size of your input file..
This User Gave Thanks to michaelrozar17 For This Post:
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

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... (7 Replies)
Discussion started by: Aswex
7 Replies

4. 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

5. 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

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