The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep latest file based on date. lweegp Shell Programming and Scripting 12 04-03-2009 03:10 AM
Grep date from ls -l GenMen Shell Programming and Scripting 1 05-01-2008 09:53 PM
grep time and date ayhanne Shell Programming and Scripting 8 01-06-2008 09:12 AM
grep using date format ali560045 Shell Programming and Scripting 8 12-11-2007 06:39 PM
ls -l | grep $date (failing) yongho Shell Programming and Scripting 1 08-01-2005 03:30 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-29-2007
scabral scabral is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 2
grep for date in file

Hi,

i have a script that stores the date in a variable as follows:

DATESTAMP=`date +"%m%d%Y"`

I also have another file called HOLIDAYFILE which stores all of our holidays as follows:

01/01/2007
07/04/2007

What i need to do is use the grep statement in my script to see if DATESTAMP is in the HOLIDAYFILE and store that in another variable, let's say HOLIDAY, and if HOLIDAY has a value then do nothing and exit the script, otherwise proceed with the code.

anyone have a good grep statement that would do this?

thanks
scott
  #2 (permalink)  
Old 05-29-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,422
DATESTAMP can be made to conform to the date format you have in HOLIDaYFILE
Code:
DATESTAMP=`date +"%m/%d/%Y"`
then you can grep for it.
  #3 (permalink)  
Old 05-29-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,355
If you can't modify the format of the date in DATESTAMP, create another variable with the right format :
Code:
DATESTAMP2=`date +"%m/%d/%Y"` # Sol 1
DATESTAMP2=$(echo $DATESTAMP | sed 's_^\(..\)\(..\)_\1/\2/_') # Sol 2

if grep -q $DATESTAMP2 HOLIDAYFILE
then
   echo "Holiday !!!"
fi
Jean-Pierre.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:57 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0