Sponsored Content
Top Forums Shell Programming and Scripting script for get lines with specific time. Post 302586876 by Just Ice on Tuesday 3rd of January 2012 02:08:16 PM
Old 01-03-2012
if you have not yet started on this project or looking at a brick wall, here is a quick breakdown of what needs to happen ...

A. grab entries from the log in 5 minute increments for each hour for each day

B. sort entries according to categories

C. create and format report


i suspect that you are getting stuck with item A so here's something to help you out ... i did it using ksh in solaris 10 so you may need to modify it according to the shell you need to use and the OS you are working in ... you still need to include the parts for items B and C but that should be easier to do ... the script may run faster using perl, python or ruby so feel free to use and modify ... be sure to test in safe place before running in production area ...

btw, "`< $tmpfile`" construct does not work in some shells so use "`cat $tmpfile`" instead ...

anyways, good luck!

Code:
#! /bin/ksh 

list=/tmp/999
tmpfile=/tmp/444".tmp"
tmpdate=/tmp/444".date"
tmphour=/tmp/444".hour"
tmpatt=/tmp/444".att"
tmpok=/tmp/444".ok"
tmpno=/tmp/444".no"

grabentry(){
start=$1
end=$2

while [ $start -le $end ]
do
    eval "awk '\$1 ~ /$date/ && \$2 ~ /$hour:$start:/ {print \$0}'" $list
    start=`expr $start + 1`
    if [ $start -lt 10 ]
    then
        start=0$start
    fi
done
}


rm /tmp/444.* 2> /dev/null

## 
## uncomment next 7 lines if script performance slows
#awk -F" " '{print $1 | "sort -u"}' $list > $tmpdate
#awk -F" " '{print $2}' $list | awk -F":" '{print $1 | "sort -u"}' > $tmphour
#
#for date in `< $tmpdate`
#do
#    for hour in `< $tmphour`
#    do
for date in `awk -F" " '{print $1 | "sort -u"}' $list`                                #<--| comment out if above 7 lines are uncommented
do                                                                                    #<--|                                                                          
    for hour in `awk -F" " '{print $2}' $list | awk -F":" '{print $1 | "sort -u"}'`   #<--|
   do                                                                                 #<--|                                                                                                 
        end=4
        while [ $end -le 59 ]
        do
            if [ $end -lt 10 -a $end -ne 00 ]
            then
                end=0$end
            fi
            start=`expr $end - 4`
            if [ $start -eq 0 ]
            then
                start=00
            fi
            if [ $start -lt 10 -a $start -ne 00 ]
            then
                start=0$start
            fi
            grabentry $start $end | awk 'NF > 0' > $tmpfile.$date.$hour.$end 
            if [ ! -s $tmpfile.$date.$hour.$end ]
            then
                rm $tmpfile.$date.$hour.$end 2> /dev/null
            else
                echo "-- cutoff time is $date $hour.$end --"  ## echo line used for debugging, can be removed
                cat $tmpfile.$date.$hour.$end                 ## replace this line with code to process, create and format report
            fi
            end=`expr $end + 5`
        done
    done
done

exit 0

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script to read specific lines in a file

I have a file with contents as follows Record 1: Rejected - Error on table "DWO"."P2G_CUST_EVENTS". ORA-00001: unique constraint (DWO.CUST_EVENTS_PK) violated Record 5: Rejected - Error on table "DWO"."P2G_CUST_EVENTS". ORA-00001: unique constraint (DWO.CUST_EVENTS_PK) violated Record 6:... (5 Replies)
Discussion started by: varshanswamy
5 Replies

2. Shell Programming and Scripting

need help--script to filter specific lines from multiple txt files

Hi folks, - I have 800 txt files - those files are cisco router configs router1.txt router2.txt ... router800.txt I want to accomplish the following: - I want to have a seperate file with all the filenames that I want to process - I want a script that goes trough all those... (7 Replies)
Discussion started by: I-1
7 Replies

3. UNIX for Advanced & Expert Users

How to delete specific lines at the same time

Dear All I have a pattern which look like this: 2 20080312_10:55:35.800 Spain-Telefonica ISC 9 IAM 927535957 34670505334 f 275 COT b 700 ACM b 6577 CPG b 10726 ANM b 202195 REL f 202307 RLC :COMMA: NCI=15,FCI=2101,CPC=0A,TMR=00,USI,OFI=00: :COMMB: BCI=0214,OBI=01,ACT: :RELCAUSE:10: This... (1 Reply)
Discussion started by: zanetti321
1 Replies

4. UNIX for Dummies Questions & Answers

command for selecting specific lines from a script

I need help on following script: I need to print the lines which are in bold letters in separate file as record string("|") emp_name; string("|") emp_id; decimal("|") emp_salary; string("|") emp_status; string("\n") emp_proj; end (1 Reply)
Discussion started by: gardasgangadhar
1 Replies

5. Shell Programming and Scripting

Ending script at specific time.

Hello Everybody.. I've written the script that kick off through CRON job and kill itself by specific time. I've start time and end time specify in env file. i.e START_TIME=1500 (03:00 PM) END_TIME=0600 (06:00 AM) It always works good if my START_TIME is before midnight and my... (4 Replies)
Discussion started by: nirav_soni
4 Replies

6. UNIX for Dummies Questions & Answers

Script required to truncate all the lines except a specific snippet.

Hi, I have a file with the following structure. XXXXX........... YYYYY........... ................. .................. ZZZZZZ...... qwerty_start.............. .................. ................. .................. querty_end................ .............................. (3 Replies)
Discussion started by: abinash
3 Replies

7. Shell Programming and Scripting

script for get lines with specific date

I'm a newbie in AIX, i want to make a script for grep any lines with date bellow 20 PRINT0089-88615 data1 3072 Mon Dec 19 17:53:49 WITA 2011 PRINT0089-88616 data1 4096 Mon Dec 19 17:53:49 WITA 2011 PRINT0089-88618 data1 5120 Mon Dec 19... (7 Replies)
Discussion started by: michlix
7 Replies

8. Shell Programming and Scripting

Script to run commands at a specific time.

Hello All, I have written a script which which is working fine to a certain logic of it. But i want a part of the script to run two commands at 00:10 hrs every day. These two command are 1. rm -rf /path/to/folder 2. mail the content of a file. How do i achieve this. Thanks. ... (4 Replies)
Discussion started by: Siddheshk
4 Replies

9. Shell Programming and Scripting

Removing specific lines from script files.

Hello, Activity to perform: 1. Find all of the "*.tmp" files in a given user directory 2. Determine which ones have "find" in them. 3. Replace the "find sequence" of commands with a "list set" of commands. Example: Original file: -------------- define lastn1 = "A" define... (7 Replies)
Discussion started by: manishdivs
7 Replies

10. UNIX for Dummies Questions & Answers

Quick UNIX command to display specific lines in the middle of a file from/to specific word

This could be a really dummy question. I have a log text file. What unix command to extract line from specific string to another specific string. Is it something similar to?: more +/"string" file_name Thanks (4 Replies)
Discussion started by: aku
4 Replies
Quote(3pm)						User Contributed Perl Documentation						Quote(3pm)

NAME
XML::Quote - XML quote/dequote functions SYNOPSIS
use strict; use XML::Quote qw(:all); my $str=q{666 > 444 & "apple" < 'earth'}; print xml_quote($str)," "; # 666 &gt; 444 &amp; &quot;apple&quot; &lt; &apos;earth&apos; my $str2=q{666 &gt; 444 &amp; &quot;apple&quot; &lt; &apos;earth&apos;}; print xml_dequote($str2)," "; # 666 > 444 & "apple" < 'earth' my $str3=q{666 > 444 & "apple" < 'earth'}; print xml_quote_min($str3)," "; # 666 > 444 &amp; &quot;apple&quot; &lt; 'earth' DESCRIPTION
This module provides functions to quote/dequote strings in "xml"-way. All functions are written in XS and are very fast; they correctly process utf8, tied, overloaded variables and all the rest of perl "magic". FUNCTIONS
$quoted = xml_quote($str); This function replaces all occurences of symbols '&', '"', ''', '>', '<' to '&amp;', '&quot;', '&apos;', '&gt;', '&lt;' respectively. Returns quoted string or undef if $str is undef. $dequoted = xml_dequote($str); This function replaces all occurences of '&amp;', '&quot;', '&apos;', '&gt;', '&lt;' to '&', '"', ''', '>', '<' respectively. All other entities (for example &nbsp;) will not be touched. Returns dequoted string or undef if $str is undef. $quoted = xml_quote_min($str); This function replaces all occurences of symbols '&', '"', '<' to '&amp;', '&quot;', '&lt;' respectively. Symbols ''' and '>' are not replaced. Returns quoted string or undef if $str is undef. EXPORT
xml_quote(), xml_dequote() are exported as default. PERFORMANCE
You can use t/benchmark.pl to test the perfomance. Here is the result on my P4 box. Benchmark: timing 1000000 iterations of perl quote, xs quote... perl quote: 108 wallclock secs (88.08 usr + 0.01 sys = 88.09 CPU) @ 11351.64/s (n=1000000) xs quote: 20 wallclock secs (16.78 usr + 0.00 sys = 16.78 CPU) @ 59591.20/s (n=1000000) Benchmark: timing 1000000 iterations of perl dequote, xs dequote... perl dequote: 106 wallclock secs (85.22 usr + 0.09 sys = 85.31 CPU) @ 11721.54/s (n=1000000) xs dequote: 19 wallclock secs (15.92 usr + 0.02 sys = 15.94 CPU) @ 62743.13/s (n=1000000) AUTHOR
Sergey Skvortsov <skv@protey.ru> SEE ALSO
http://www.w3.org/TR/REC-xml <http://www.w3.org/TR/REC-xml>, perlre COPYRIGHT
Copyright 2003 Sergey Skvortsov <skv@protey.ru>. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2008-06-26 Quote(3pm)
All times are GMT -4. The time now is 09:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy