Sponsored Content
Full Discussion: Optimize shell code
Top Forums Shell Programming and Scripting Optimize shell code Post 302434970 by sandy1028 on Tuesday 6th of July 2010 03:26:02 AM
Old 07-06-2010
Optimize shell code

Code:
#!/usr/bin/perl
use strict;
use warnings;

use Date::Manip;
my $date_converted = UnixDate(ParseDate("3 days ago"),"%e/%h/%Y");
open FILE,">$ARGV[0]";

while(<DATA>){

my @tab_delimited_array = split(/\t/,$_);
  $tab_delimited_array[3] =~ s/^\[//;
  $tab_delimited_array[3] =~ s/^\-//;
        my $converted_date = Date_ConvTZ( UnixDate($tab_delimited_array[3],"%Y%m%d%H:%M:%S"),'GMT','PST');
        my $pst_converted_date = UnixDate($converted_date,"%e/%h/%Y:%H:%M:%S");
        $pst_converted_date =~ s/^\s//g;
        my $extracted_YMD=UnixDate($converted_date,"%e/%h/%Y");
if($extracted_YMD =~ m/$date_converted/){
print FILE $_;
}
}

close FILE;
close DATA;


__DATA__
66.249.65.43    www.cabc.com    -       3/Jul/2010:19:00:01     +0000   "GET http://www.abc.com HTTP/1.1"       200     0.730   7362    0       0       -       -       Mozilla/5.0+(compatible;+Googl/2.1;+\+http://www.google.com/bot.html)   TCP_MISS
66.249.65.43    www.cabc.com    -       4/Jul/2010:19:00:01     +0000   "GET http://www.abc.com HTTP/1.1"       200     0.730   7362    0       0       -       -       Mozilla/5.0+(compatible;+Googl/2.1;+\+http://www.google.com/bot.html)   TCP_MISS
66.249.65.43    www.cabc.com    -       2/Jul/2010:09:00:01     +0000   "GET http://www.abc.com HTTP/1.1"       200     0.730   7362    0       0       -       -       Mozilla/5.0+(compatible;+Googl/2.1;+\+http://www.google.com/bot.html)   TCP_MISS
66.249.65.43    www.cabc.com    -       3/Jul/2010:09:00:01     +0000   "GET http://www.abc.com HTTP/1.1"       200     0.730   7362    0       0       -       -       Mozilla/5.0+(compatible;+Googl/2.1;+\+http://www.google.com/bot.html)   TCP_MISS



---------- Post updated at 02:26 AM ---------- Previous update was at 02:25 AM ----------

The file is very large and it takes long time to execute.
The input is tab delimited file
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

optimize shell script (snapshots)

I've a script to do some snapshots but the time it does so is very different... once i got a snapshot under 1 sec, on the other hand it took 3 sec, but nothing else changed, i didnt even move the cursor or something. I put the script on a ramdisk and its faster, but still swing from under 1... (1 Reply)
Discussion started by: mcW
1 Replies

2. Shell Programming and Scripting

pl help me to Optimize the given code

Pl help to me to write the below code in a simple way ... i suupose to use this code 3 to 4 places in my makefile(gnu) .. **************************************** @for i in $(LIST_A); do \ for j in $(LIST_B); do\ if ;then\ echo "Need to sign"\ echo "List A = $$i , List B =$$j"\ ... (2 Replies)
Discussion started by: pk_arun
2 Replies

3. Shell Programming and Scripting

Optimize the nested IF

Hi, I have to assign a value for a varaiable based on a Input. I have written the below code: if then nf=65 elif then nf=46 elif then nf=164 elif then nf=545 elif then nf=56 elif then (3 Replies)
Discussion started by: machomaddy
3 Replies

4. Shell Programming and Scripting

Can someone please help me optimize my code (script searches subdirectories)?

Here is my code. What it does is it reads an input file (input.txt which contains roughly 2,000 search phrases) and searches a directory for files that contains the search phrase. The directory contains roughly 1900 files and 84 subdirectories. The output is a file (output.txt) that shows only the... (23 Replies)
Discussion started by: jl487
23 Replies

5. UNIX for Dummies Questions & Answers

optimize if block : shell script

Hi, I need a shell script to determine if a no. is either even, greater than 4, less than 8 SHELL : ksh OS : RHEL 6 this is the if block of the script mod=`expr $num % 2` if || || then echo "No. is either even or greater than 4 or less than 8" fi this code works... (2 Replies)
Discussion started by: sam05121988
2 Replies

6. Shell Programming and Scripting

Optimize my mv script

Hello, I'm wondering if there is a quicker way of doing this. Here is my mv script. d=/conversion/program/out cd $d ls $d > /home/tempuser/$$tmp while read line ; do a=`echo $line|cut -c1-5|sed "s/_//g"` b=`echo $line|cut -c16-21` if ;then mkdir... (13 Replies)
Discussion started by: whegra
13 Replies

7. Shell Programming and Scripting

Optimize shell script to run faster

data.file: contact { contact_name=royce-rolls modified_attributes=0 modified_host_attributes=0 modified_service_attributes=0 host_notification_period=24x7 service_notification_period=24x7 last_host_notification=0 last_service_notification=0 host_notifications_enabled=1... (8 Replies)
Discussion started by: SkySmart
8 Replies

8. Shell Programming and Scripting

Looking to optimize code

Hi guys, I feel a bit comfortable now doing bash scripting but I am worried that the way I do it is not optimized and I can do much better as to how I code. e.g. I have a whole line in a file from which I want to extract some values. Right now what I am doing is : STATE=`cat... (5 Replies)
Discussion started by: Junaid Subhani
5 Replies

9. Shell Programming and Scripting

Optimize awk code

sample data.file: 0,mfrh_green_screen,1454687485,383934,/PROD/G/cicsmrch/sys/unikixmain.log,37M,mfrh_green_screen,28961345,0,382962--383934 0,mfrh_green_screen,1454687785,386190,/PROD/G/cicsmrch/sys/unikixmain.log,37M,mfrh_green_screen,29139568,0,383934--386190... (7 Replies)
Discussion started by: SkySmart
7 Replies

10. Shell Programming and Scripting

Help Optimize the Script Further

Hi All, I have written a new script to check for DB space and size of dump log file before it can be imported into a Oracle DB. I'm relatively new to shell scripting. Please help me optimize this script further. (0 Replies)
Discussion started by: narayanv
0 Replies
Date::Manip::TZdata(3)					User Contributed Perl Documentation				    Date::Manip::TZdata(3)

NAME
Date::Manip::TZdata -- Internal module for working with the tzdata files SYNOPSIS
use Date::Manip::TZdata; $tzd = new Date::Manip::TZdata($dir); DESCRIPTION
This module is not intended for public use. It is used internally by the scripts used to analyze the time zone database and generate the modules for each time zone. The module is included in the distribution solely for the sake of completeness. Currently, no support is offered for this module, and it can (and may) change without notice. This module consists of routines for working with the tzdata files obtained from ftp://elsie.nci.nih.gov/pub/ . These files are updated several times a year and are the basis for time zone descriptions for most computer systems. At some point, I am interested in making this module a direct interface to the tzdata files, but in the limited amount of time I have to work on perl modules, other modifications to Date::Manip are much higher priority, so I'm not sure when (or if) this will ever happen. ROUTINES
new use Date::Manip::TZdata; $tzd = new Date::Manip::TZdata($dir); This finds and reads in all the tzdata. If $dir is passed in, it is the directory where a tzdata directory is located. It defaults to the current directory. KNOWN LIMITATIONS
Some assumptions and limitations are assumed in the logic of this module. When a time change occurs, the time may change backwards or forwards. Time changes rules are listed on a per-year basis. It is assumed that time changes will not occur so close to the end or start of the year as to cross the year boundary (in other words, the year will not change as a result of the time change). This is not accounted for, and it is hoped that this situation will never occur. Also, because this module is strictly limited to 4 digit positive years (regardless of whether it is wallclock or universal time), and because various parts of the module switch back and forth, valid times for this module are from Jan 2, 0001 to Dec 30, 9999. This ensures that conversions from wallclock to universal or vice versa will never make dates occur in the year 0000 or 10000. KNOWN BUGS
None known. BUGS AND QUESTIONS
Please refer to the Date::Manip man page for information on submitting bug reports or questions to the author. AUTHOR
Sullivan Beck (sbeck@cpan.org) perl v5.12.1 2010-01-12 Date::Manip::TZdata(3)
All times are GMT -4. The time now is 12:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy