Formatting the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatting the file
# 8  
Old 04-28-2010
Code:
#!/usr/bin/awk -f
BEGIN {
   FS = "[\" :]+";
}

{
   sub(FS "$", "");  
   DateTime    = $1 ":" $2 ":" $3 ":" $4;
   Action      = $5;
   ActionLower = tolower($5);

   if (ActionLower == "changed") {
      if (ResetPath) Path = "";
      ResetPath = 0;
      Path = (Path ? Path "/" : "") $8;
      next;
   }

   ResetPath = 1;

   if (ActionLower == "deleted") {
      File   = $6;
      Status = $NF;
      print DateTime,Path,Action,File,"-",Status
      next;
   }

   if (ActionLower == "uploaded") {
      File   = $6;
      Status = $NF;
      if (Status ~ /^[0-9]+$/) Status = "SUCCESSFUL " Status;
      print DateTime,Path,Action,File,"-",Status
      next;
   }
}

Jean-Pierre.
This User Gave Thanks to aigles For This Post:
# 9  
Old 04-29-2010
Excellent!!! Thanks a lot again..... :-) :-) :-)


I need one more help in this.. Can you please help me in that..

Code:
#############################################################################################################          
19/Apr/2010:07:06:19 "Changed directory to dms-imrm/Fort_Wayne/Parkview" - SUCCESSFUL        
19/Apr/2010:07:06:19 "Changed directory to Requisitions" - SUCCESSFUL        
19/Apr/2010:07:06:21 "Deleted 668027 axxxx1.ZIP" - FAILED        
19/Apr/2010:07:06:23 "Uploaded 668027 axxxx2.ZIP" ---- FILE SIZE(Bytes) :5583273       
#############################################################################################################

if I have a space in the file name as above this script is not taking the file name fully instead the first field only ie 668027 . yeah i know that the logic you are using is bit different in this case. Can you please help me in resolving that?
# 10  
Old 04-29-2010
assuming the actual file name will always be the next "word" in the sequence, you'd want to also define a name-type variable using $7.
# 11  
Old 04-29-2010
Try this new version :
Code:
#!/usr/bin/awk -f
BEGIN {
   FS = "[\" :]+";
}

{
   sub(FS "$", "");
   DateTime    = $1 ":" $2 ":" $3 ":" $4;
   Action      = $5;
   ActionLower = tolower($5);

   if (ActionLower == "changed") {
      if (ResetPath) Path = "";
      ResetPath = 0;
      Path = (Path ? Path "/" : "") $8;
      next;
   }

   ResetPath = 1;

   if (ActionLower == "deleted") {
      File   = $0;
      sub(".*\"" Action " *", "", File);
      sub("\".*", "", File);
      Status = $NF;
      print DateTime,Path,Action,File,"-",Status
      next;
   }

   if (ActionLower == "uploaded") {
      File   = $0;
      sub(".*\"" Action " *", "", File);
      sub("\".*", "", File);
      Status = $NF;
      if (Status ~ /^[0-9]+$/) Status = "SUCCESSFUL " Status;
      print DateTime,Path,Action,File,"-",Status
      next;
   }
}

Input file:
Code:
19/Apr/2010:07:06:19 "Changed directory to dms-imrm/Fort_Wayne/Parkview" - SUCCESSFUL
19/Apr/2010:07:06:19 "Changed directory to Requisitions" - SUCCESSFUL
19/Apr/2010:07:06:21 "Deleted 668027.ZIP" - FAILED
19/Apr/2010:07:06:23 "Uploaded 668027.ZIP" ---- FILE SIZE(Bytes) :5583273

20/Apr/2010:07:06:19 "Changed directory to dms-imrm/Fort_Wayne/Parkview" - SUCCESSFUL
20/Apr/2010:07:06:19 "Changed directory to Requisitions-2" - SUCCESSFUL
20/Apr/2010:07:06:21 "Deleted 668027 axxxx1.ZIP" - FAILED
20/Apr/2010:07:06:23 "Uploaded 668027 axxxx2.ZIP" ---- FILE SIZE(Bytes) :5583273

Output:
Code:
19/Apr/2010:07:06:21 dms-imrm/Fort_Wayne/Parkview/Requisitions Deleted 668027.ZIP - FAILED
19/Apr/2010:07:06:23 dms-imrm/Fort_Wayne/Parkview/Requisitions Uploaded 668027.ZIP - SUCCESSFUL 5583273
20/Apr/2010:07:06:21 dms-imrm/Fort_Wayne/Parkview/Requisitions-2 Deleted 668027 axxxx1.ZIP - FAILED
20/Apr/2010:07:06:23 dms-imrm/Fort_Wayne/Parkview/Requisitions-2 Uploaded 668027 axxxx2.ZIP - SUCCESSFUL 5583273

Jean-Pierre.
# 12  
Old 04-29-2010
SmilieSmilieSmilieSmilieSmilieSmilieSmilieSmilieSmilieSmilie


Superb....!!!!

---------- Post updated at 07:58 AM ---------- Previous update was at 07:58 AM ----------

Thanks a lllooooottttt
# 13  
Old 05-13-2010
Quote:
Originally Posted by aigles
Try the following AWK program :
Code:
#!/usr/bin/awk -f
BEGIN {
   FS = "[\" :]+";
}

{
   sub(FS "$", "");
   Action      = $5;
   ActionLower = tolower($5);

   if (ActionLower == "changed") {
      if (ResetPath) Path = "";
      ResetPath = 0;
      Path = (Path ? Path "/" : "") $8;
      next;
   }

   ResetPath = 1;

   if (ActionLower == "deleted") {
      File   = $6;
      Status = $NF;
      print $1,Path,Action,File,"-",Status
      next;
   }

   if (ActionLower == "uploaded") {
      File   = $6;
      Status = $NF;
      if (Status ~ /^[0-9]+$/) Status = "SUCCESSFUL " Status;
      print $1,Path,Action,File,"-",Status
      next;
   }
}

Output:
Code:
19/Apr/2010 dms-imrm/Fort_Wayne/Parkview/Requisitions Deleted 668027.ZIP - FAILED
19/Apr/2010 dms-imrm/Fort_Wayne/Parkview/Requisitions Uploaded 668027.ZIP - SUCCESSFUL 5583273

Jean-Pierre.
One more question...

How can i keep the ################## there?

#################################################################################################### #########
19/Apr/2010:07:05:50 dms-imrm/Fort_Wayne/Parkview/Requisitions Deleted 668027.ZIP FAILED 0
19/Apr/2010:07:05:57 dms-imrm/Fort_Wayne/Parkview/Requisitions Uploaded 668027.ZIP SUCCESSFUL 5583273
#################################################################################################### #########
# 14  
Old 05-13-2010
Quote:
Originally Posted by Tuxidow
One more question...

How can i keep the ################## there?

#################################################################################################### #########
19/Apr/2010:07:05:50 dms-imrm/Fort_Wayne/Parkview/Requisitions Deleted 668027.ZIP FAILED 0
19/Apr/2010:07:05:57 dms-imrm/Fort_Wayne/Parkview/Requisitions Uploaded 668027.ZIP SUCCESSFUL 5583273
#################################################################################################### #########
Code:
#!/usr/bin/awk -f
BEGIN {
   FS = "[\" :]+";
}

/^#+/ {
   print;
   next;
}

{
   sub(FS "$", "");
   Action      = $5;
   . . . . .

Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Formatting data in a raw file by using another mapping file

Hi All, i have a requirement where i need to format the input RAW file ( which is CSV) by using another mapping file(also CSV file). basically i am getting feed file with dynamic headers by using mapping file (in that target field is mapped with source filed) i have to convert the raw file into... (6 Replies)
Discussion started by: ravi4informatic
6 Replies

2. Shell Programming and Scripting

Formatting file data to another file (control character related)

I have to write a program to read data from files and then format into another file. However, I face a strange problem related to control character that I can't understand and solve. The source file is compose of many lines with such format: T_NAME|P_NAME|P_CODE|DOCUMENT_PATH|REG_DATE ... (3 Replies)
Discussion started by: hk6279
3 Replies

3. Shell Programming and Scripting

File Formatting

Hi, I have requirement to format the file.My input file tab(\t) saperated. File format is:- 93 WARNING Sat Mar 17 20:31:59 2012 Sequential_File_0,0: Missing record delimiter "\r\n", saw EOF instead 94 WARNING Sat Mar 17 20:31:59 2012 Sequential_File_0,0: Import... (4 Replies)
Discussion started by: prasson_ibm
4 Replies

4. Shell Programming and Scripting

File formatting

Hi, I have a file which contains data in this format # User@Host: abc @ Id: 0000000 # Query_time: 0.000070 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0 SET timestamp=00000000; SELECT @@version, @@version_comment; # User@Host: abcd @ Id: 00000000 # Query_time: 0.000228 ... (6 Replies)
Discussion started by: arijitsaha
6 Replies

5. Shell Programming and Scripting

File formatting

I need to count the number of lines between two sets of pattern in a file and delete those lines from that file e.g From jyotiv@yahoo.com test test2 test3 test4 test5 test6 From Jyotiv@yahoo.com So count lines from test to test6 and delete it from the start of file till next From... (1 Reply)
Discussion started by: jyotiv
1 Replies

6. Shell Programming and Scripting

File Formatting

Hi, Need to delete all the records prior to pattern (INSERT/UPDATE/DELETE). If ' is available, then need to retain it. Input ====================== l_s := ' INSERT INTO TEST' l_P PD := ' UPDATE INTO TEST' l_D := ' DELETE INTO TEST' This is test Output ======================... (1 Reply)
Discussion started by: saurabhbaisakhi
1 Replies

7. Shell Programming and Scripting

File Formatting

Hi, Need to delete all the records prior to pattern (INSERT/UPDATE/DELETE). If ' is available, then need to retain it. Input ====================== l_s := ' INSERT INTO TEST' l_P PD := ' UPDATE INTO TEST' l_D := ' DELETE INTO TEST' This is test Input ======================... (1 Reply)
Discussion started by: saurabhbaisakhi
1 Replies

8. UNIX for Dummies Questions & Answers

Formatting a file.

I want to format a file to limit record length = 100, in each line. Any idea how i can do this? (1 Reply)
Discussion started by: abhilasha
1 Replies

9. Shell Programming and Scripting

Help with formatting of file.

I have a file with following file format - DMCRH|||83000171|||14022008||0430|||8956612.23|J|||3571235|1378452|23468|6894|9234| DMCRH|||83000215|||15092007||0480|||121.33|J|||LineID003|RefNumSP003|RefNumMem003|0004|0003| What i need done is - 1. Cut the firt four digits of the date (eg 1402... (3 Replies)
Discussion started by: divz
3 Replies

10. Shell Programming and Scripting

Formatting a file

Hi All, I have been trying to format a file using sed. I can't seem to get the syntax right. I want to append the next line delemited by a comma or a comma and double quotes. Here is an example of the file I'm tring to format: Before formatting: 00324 03A0312 BRI-u24 0000324 01 H-12... (4 Replies)
Discussion started by: cstovall
4 Replies
Login or Register to Ask a Question