Sponsored Content
Full Discussion: Quick Help in shell script
Top Forums Shell Programming and Scripting Quick Help in shell script Post 302423928 by durden_tyler on Sunday 23rd of May 2010 01:13:40 PM
Old 05-23-2010
Quote:
Originally Posted by KuldeepSinghTCS
...
Code:
 Tue Mar 11 05:17:41 GMT 2008 until: Fri Mar 09 05:17:41 GMT 2018
 Thu Jun 12 18:36:48 GMT 2008 until: Sun Jun 10 18:36:48 GMT 2018
 Thu Jun 12 18:29:42 GMT 2008 until: Sun Jun 10 18:29:42 GMT 2018
 Tue Mar 11 05:18:02 GMT 2008 until: Fri Mar 09 05:18:02 GMT 2018
 Tue May 27 16:29:27 GMT 2008 until: Fri May 25 16:29:27 GMT 2018
 Tue May 27 16:40:04 GMT 2008 until: Fri May 25 16:40:04 GMT 2018
 Tue Mar 11 05:18:02 GMT 2008 until: Fri Mar 09 05:18:02 GMT 2018
 Tue May 27 16:29:27 GMT 2008 until: Fri May 25 16:29:27 GMT 2018
 Tue May 27 16:40:04 GMT 2008 until: Fri May 25 16:40:04 GMT 2018

Can you help me to highlight those lines from input files which are having "until:somedate" are older then today in red and those about to come in 3 months time as orange.
the time stamp will be taken from input file after the until.
...
Something like this maybe ?

Code:
$ 
$ 
$ cat f9
Tue Mar 11 05:17:41 GMT 2008 until: Fri Mar 09 05:17:41 GMT 2010
Thu Jun 12 18:36:48 GMT 2008 until: Sun Jun 10 18:36:48 GMT 2010
Thu Jun 12 18:29:42 GMT 2008 until: Sun Jun 10 18:29:42 GMT 2010
Tue Mar 11 05:18:02 GMT 2008 until: Fri Mar 09 05:18:02 GMT 2010
Tue May 27 16:29:27 GMT 2008 until: Fri May 25 16:29:27 GMT 2010
Tue May 27 16:40:04 GMT 2008 until: Fri May 25 16:40:04 GMT 2010
Tue Mar 11 05:18:02 GMT 2008 until: Fri Mar 09 05:18:02 GMT 2010
Tue May 27 16:29:27 GMT 2008 until: Fri May 25 16:29:27 GMT 2010
Tue May 27 16:40:04 GMT 2008 until: Fri May 25 16:40:04 GMT 2010
Tue May 27 16:40:04 GMT 2008 until: Sun Aug 22 16:40:04 GMT 2010
Tue May 27 16:40:04 GMT 2008 until: Mon Aug 23 16:40:04 GMT 2010
Tue May 27 16:40:04 GMT 2008 until: Tue Aug 24 16:40:04 GMT 2010
Tue May 27 16:40:04 GMT 2008 until: Sat Dec 25 16:40:04 GMT 2010
$ 
$ 
$ cat -n f9.pl
     1    #!/usr/bin/perl -w
     2    use Date::Calc qw(Parse_Date Today Delta_Days Add_Delta_YMD Date_to_Days);
     3    $file = "f9";
     4    @y = Today();
     5    @z = Add_Delta_YMD(@y, 0,3,0);
     6    open (IN, $file) or die "Can't open $file: $!";
     7    while (<IN>) {
     8      chomp;
     9      /^.*?until: (.*?)$/ and $testdate = $1;
    10      @x = Parse_Date ($testdate);
    11      $dd = Delta_Days(@y, @x);
    12      print $_,"\t=>\t";
    13      if ($dd < 0) {
    14        print "Earlier than today";
    15      } elsif (Delta_Days(@x, @z) >= 0) {
    16        print "Between today and the next 3 months";
    17      } else {
    18        print "Later than the next 3 months";
    19      }
    20      print "\n";
    21    }
    22    close (IN) or die "Can't close $file: $!";
    23    
$ 
$ 
$ perl f9.pl
Tue Mar 11 05:17:41 GMT 2008 until: Fri Mar 09 05:17:41 GMT 2010    =>    Earlier than today
Thu Jun 12 18:36:48 GMT 2008 until: Sun Jun 10 18:36:48 GMT 2010    =>    Between today and the next 3 months
Thu Jun 12 18:29:42 GMT 2008 until: Sun Jun 10 18:29:42 GMT 2010    =>    Between today and the next 3 months
Tue Mar 11 05:18:02 GMT 2008 until: Fri Mar 09 05:18:02 GMT 2010    =>    Earlier than today
Tue May 27 16:29:27 GMT 2008 until: Fri May 25 16:29:27 GMT 2010    =>    Between today and the next 3 months
Tue May 27 16:40:04 GMT 2008 until: Fri May 25 16:40:04 GMT 2010    =>    Between today and the next 3 months
Tue Mar 11 05:18:02 GMT 2008 until: Fri Mar 09 05:18:02 GMT 2010    =>    Earlier than today
Tue May 27 16:29:27 GMT 2008 until: Fri May 25 16:29:27 GMT 2010    =>    Between today and the next 3 months
Tue May 27 16:40:04 GMT 2008 until: Fri May 25 16:40:04 GMT 2010    =>    Between today and the next 3 months
Tue May 27 16:40:04 GMT 2008 until: Sun Aug 22 16:40:04 GMT 2010    =>    Between today and the next 3 months
Tue May 27 16:40:04 GMT 2008 until: Mon Aug 23 16:40:04 GMT 2010    =>    Between today and the next 3 months
Tue May 27 16:40:04 GMT 2008 until: Tue Aug 24 16:40:04 GMT 2010    =>    Later than the next 3 months
Tue May 27 16:40:04 GMT 2008 until: Sat Dec 25 16:40:04 GMT 2010    =>    Later than the next 3 months
$ 
$

tyler_durden
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need quick help with basic FIND in korn shell

I gotta make a script to find files, not quite sure whats wrong... filename is search i run it search ass* $HOME ass* is the filename and in my script i have... find $2 -name $1 -print but it never works, anyone know what i gotta fix? and does anyone know the difference... (6 Replies)
Discussion started by: Freakytah
6 Replies

2. Shell Programming and Scripting

need a quick basic shell script help

im trying to run the below if command ifconfig -a |grep 10.100.120.21 gives me below output inet addr:10.100.120.21 Bcast:10.100.120.255 Mask:255.255.255.0 i just want a basic shell which says if above exists then continue how would i do this? (6 Replies)
Discussion started by: eb222
6 Replies

3. Shell Programming and Scripting

Quick help needed in the Shell Script

Hiii, i have a doubt here-- I have to take backup of all the files inside directory dir(logs,tmp,corefiles) at the location $BackupLocation.i should take the backup of logs,tmp,corefiles inside the $BackupLocation directory and then remove the files and touch the files inside the directory... (1 Reply)
Discussion started by: namishtiwari
1 Replies

4. Shell Programming and Scripting

quick script C shell

Cool. I played with scripts at home over the weekend. Come to find out not working on other shells. I have linux/bash at home, but now I'm trying on Solaris csh. How would I write the following script for Solaris C shell? ---------- #!/bin/bash NBR=231 for ((i = 0; i < $NBR; i++ )) do... (1 Reply)
Discussion started by: ajp7701
1 Replies

5. UNIX for Advanced & Expert Users

Guidance needed for quick script

Hi all, I am trying to get the exception count daily from a log file which is more than 1 GB in size. I am using loops which get the count of the exception and transaction. But i need to take this exception count for a time frame from 5.00 am to 5:00 pm. I Think I can use to exact the... (4 Replies)
Discussion started by: senthilkumar_ak
4 Replies

6. Shell Programming and Scripting

Quick Question on sed command in shell script

Hello, I have the following line in one of my shell scripts. It works fine when the search string($SERACH_STR) exists in the logfile($ALERTLOG) but if the search string does not exist this line errors out at run time. Is there a way to make this line return 0 if it is not able to find the... (4 Replies)
Discussion started by: luft
4 Replies

7. Shell Programming and Scripting

Quick question: calling c-shell script from bash

Hello, I have a quick reference question: I have a very long, but fairly straigtforward script written in c-shell. I was wondering if it is possible to call this script from bash (for ex. having a function in bash script which calls the c-shell script when necessary), and if so, are there any... (1 Reply)
Discussion started by: lapiduslost
1 Replies

8. Shell Programming and Scripting

How to make a quick search through a script?

Hello, I have a file that has more than 300K records (i.e contains numbers). I need to take these records and than search them in 40 files while each file has more than 1.8 million records. I wrote a script, but its very slow and takes alot of time. I have tried to split my 300k records in 6... (7 Replies)
Discussion started by: umarsatti
7 Replies

9. Shell Programming and Scripting

Quick script to rename files

so I have about 30k jpg files that I need to rename in one hit. The current filename format is: x_surname_firstname_y_20141115_OS_(z) where x, y and z are numbers of various lengths the new filename format needs to be surname_firstname_y_OS_(z) So I basically need to remove the first... (23 Replies)
Discussion started by: jonesal2
23 Replies
All times are GMT -4. The time now is 05:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy