👤
Home Man
Search
Today's Posts
Register

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

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

👤 Login to reply

 
Thread Tools Search this Thread
# 1  
Old 12-02-2008
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
# 2  
Old 12-02-2008
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
# 3  
Old 12-02-2008
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 12-02-2008
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
# 5  
Old 12-02-2008
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
# 6  
Old 12-02-2008
Could you possibly run me through what each line of the code is doing so i can alter it if need be regards ross
# 7  
Old 12-02-2008
And thanks works great on the text I provided above
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How can I remove partial duplicates and manipulate text? tara123 UNIX for Beginners Questions & Answers 4 12-30-2017 11:53 PM
Manipulate the text file in UNIX siva.pitchai Shell Programming and Scripting 6 11-27-2014 02:40 AM
Logfile monitoring with logfile replacement Warluck Shell Programming and Scripting 3 11-15-2014 02:33 AM
Need help to manipulate data using script nith_anandan Shell Programming and Scripting 8 11-28-2013 10:55 PM
Shell script to manipulate files vedanta UNIX for Advanced & Expert Users 0 04-17-2013 04:19 PM
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
Shell script to manipulate a file deo_kaustubh Shell Programming and Scripting 2 08-09-2010 08:41 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 09:21 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?