Formatting the file

#############################################################################################################          
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       
############################################################################################################# 

I have a sample file like above which I got from a log file with the help of script.

Can anybody help me in re-formatiing it into

#############################################################################################################          
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
#############################################################################################################

Hi.

My eyes may be playing tricks, but they look the same :slight_smile:

Hi,

What is the difference between above two files.

I know one magic UNIX command - it's called 'cp' :wink:
What's the diff between the 2 files?

Sorry :wink:

#############################################################################################################          
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
#############################################################################################################

Try the following AWK program :

#!/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:

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.

excellent!! :slight_smile: :slight_smile: thanks a lot... no ton... :slight_smile:

only thing which i am missing is the time stamp. Im trying to fix it.. :b::b:

---------- Post updated at 08:24 AM ---------- Previous update was at 07:40 AM ----------

I could not get the time stamp included. Can you please help me in that..?

like 19/Apr/2010:07:05:50 dms-imrm/Fort_Wayne/Parkview/Requisitions Deleted 668027.ZIP - FAILED

#!/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.

1 Like

Excellent!!! Thanks a lot again..... :slight_smile: :slight_smile: :slight_smile:

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

#############################################################################################################          
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?

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.

Try this new version :

#!/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:

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:

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.

:b::b::b::b::b::b::b::b::b::b:

Superb....!!!!

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

Thanks a lllooooottttt

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
#############################################################################################################

#!/usr/bin/awk -f
BEGIN {
   FS = "[\" :]+";
}

/^#+/ {
   print;
   next;
}

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

Jean-Pierre.