Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Script to manipulate logfile text

Shell Programming and Scripting


Tags
shell script, shell scripting, unix scripting, unix scripting basics

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-02-2008   -   Original Discussion by rosspaddock
rosspaddock's Unix or Linux Image
rosspaddock rosspaddock is offline
Registered User
 
Join Date: Dec 2008
Last Activity: 9 December 2008, 2:30 PM EST
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Script to manipulate logfile text

Hi guys, I was wandering if a Shell guru could give me some advice on tackling a problem.

I have used a mixture of grep, cut and awk to get data from a log file in the following format:



Code:
14/11/08 10:39:      Checking currenly    :  Enabled
14/11/08 10:39:      Records allocated    :  221
14/11/08 10:39:      Records Freed         :  0
14/11/08 10:39:      Records Aged          :  56

list continues in same format etc.......

What I would now like to do is pipe it into another bit of script which would leave it in a comma delimited format with date timestamp so i can throw it into a sql data base, format like so.

14/11/08 , 10:39 , Enabled , 221 , 0 , 56

I have come a little stuck and am not sure how I would do this so any advice would be much appreciated.

Last edited by Franklin52; 12-02-2008 at 02:06 PM.. Reason: adding code tags
Sponsored Links
    #2  
Old Unix and Linux 12-02-2008   -   Original Discussion by rosspaddock
rosspaddock's Unix or Linux Image
rosspaddock rosspaddock is offline
Registered User
 
Join Date: Dec 2008
Last Activity: 9 December 2008, 2:30 PM EST
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Just to add a quick note the formatting has slightly messed after posting to the forum, everything is in straight clear cut colums with set character positions
Sponsored Links
    #3  
Old Unix and Linux 12-02-2008   -   Original Discussion by rosspaddock
joeyg's Unix or Linux Image
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 19 June 2018, 11:00 AM EDT
Location: Within two miles of a Dunkin donuts.
Posts: 2,484
Thanks: 144
Thanked 209 Times in 184 Posts
Unix or Linux Question Question

How do you know how far to carry the
Enabled , 221 , 0 , 56 ?

Are you grouping things with the same date/time, or until some other message comes up?
    #4  
Old Unix and Linux 12-02-2008   -   Original Discussion by rosspaddock
rosspaddock's Unix or Linux Image
rosspaddock rosspaddock is offline
Registered User
 
Join Date: Dec 2008
Last Activity: 9 December 2008, 2:30 PM EST
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Those values are taken from the last column until the end of the file, the date time stamp is the same due to earlier text processing. thats why I just want to end up with

14/11/08 , 10:39 , Enabled , 221 , 0 , 56
Sponsored Links
    #5  
Old Unix and Linux 12-02-2008   -   Original Discussion by rosspaddock
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 5 June 2018, 9:29 AM EDT
Location: The Netherlands
Posts: 7,747
Thanks: 139
Thanked 558 Times in 520 Posts
Try this:



Code:
awk '{
s=$1" , "substr($2,1,5)" , "$6
for(i=1;i<4;i++) {
  getline;s=s" , "$6
}
print s}' file

Regards
Sponsored Links
    #6  
Old Unix and Linux 12-02-2008   -   Original Discussion by rosspaddock
rosspaddock's Unix or Linux Image
rosspaddock rosspaddock is offline
Registered User
 
Join Date: Dec 2008
Last Activity: 9 December 2008, 2:30 PM EST
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Could you possibly run me through what each line of the code is doing so i can alter it if need be regards ross
Sponsored Links
    #7  
Old Unix and Linux 12-02-2008   -   Original Discussion by rosspaddock
rosspaddock's Unix or Linux Image
rosspaddock rosspaddock is offline
Registered User
 
Join Date: Dec 2008
Last Activity: 9 December 2008, 2:30 PM EST
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
And thanks works great on the text I provided above
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Manipulate string in shell script Dev_Sharma987 Shell Programming and Scripting 3 04-17-2011 03:19 AM
Question on how to manipulate a SIMPLE text file (using awk?) ninjagod123 UNIX for Dummies Questions & Answers 2 10-14-2010 11:30 AM
sed script to manipulate the /etc/passwd file Pauline mugisha Shell Programming and Scripting 2 11-29-2009 06:56 PM
manipulate text for openldap import/export question. i2ambler Shell Programming and Scripting 0 10-23-2009 01:56 PM
using sed to manipulate text in files Jefferson333 UNIX for Dummies Questions & Answers 3 08-09-2008 03:26 AM



All times are GMT -4. The time now is 11:04 AM.