The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Selecting a line value unibboy Shell Programming and Scripting 4 02-12-2008 01:41 PM
tar - Selecting target dir GNMIKE UNIX for Dummies Questions & Answers 3 11-05-2005 02:52 AM
selecting each paragraph and put it into a file...help me swamymns Shell Programming and Scripting 2 10-04-2005 08:46 AM
Selecting information from several web pages... Vishnu UNIX for Dummies Questions & Answers 2 11-06-2002 01:04 PM
Selecting unknown string. Cameron UNIX for Dummies Questions & Answers 2 12-18-2001 11:48 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-28-2003
Registered User
 

Join Date: Dec 2003
Posts: 17
Stumble this Post!
Exclamation Selecting the middle date!

Hi everyone

really need some help with this one.

Ive to write a script where the middle date has to be checked and made sure that it is the current date.

281220032812200328122003

This is the format ive to check the date in the middle is the current date.

Can anyone help me with this one - PLEASE.

Thanks
Forum Sponsor
  #2 (permalink)  
Old 12-28-2003
google's Avatar
Moderator
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Stumble this Post!
What system are you running? What shell? Also, can you elaborate just a bit more as to how the data looks? Is this date line in every record, or just a header or trailer record of a file? Does the example line you posted represent a complete line?

You can skin this cat in several ways. This assumes the date line is in every record within a file. Here is one:

Code:
FILE_DATE=$(cut -c 9-15 data_file | head -1)
TODAYS_DATE=$(date +'%d%m%Y')

if [ ${FILE_DATE} != ${TODAYS_DATE} ]
 then
   echo "Dates Dont Match"
fi
  #3 (permalink)  
Old 12-28-2003
Registered User
 

Join Date: Nov 2003
Location: HK
Posts: 53
Stumble this Post!
vcardo10,

Do the format of 1st to 9th of month and Jan to Sep become one digit? Otherwise Google's script may need a improvement.
__________________
tikual :)
  #4 (permalink)  
Old 12-29-2003
Registered User
 

Join Date: Dec 2003
Posts: 17
Stumble this Post!
The Shell is Korn shell

The date line in the example is the content of a file which ive to get the script to check.

Does this elaborate enough?

Thanks
  #5 (permalink)  
Old 12-29-2003
Registered User
 

Join Date: Dec 2003
Location: India
Posts: 50
Stumble this Post!
I am not clear with your question, I assume you are asking for today' s date 29122003 to be searched in a file, then the below will work

str=`date -u +%d%m%Y`
grep $str filename

if [ $? -ne 0 ]
then
echo "Date was not found"
exit 1
fi

Regards
JK

Last edited by jayakhanna; 12-29-2003 at 07:46 PM.
  #6 (permalink)  
Old 12-29-2003
Registered User
 

Join Date: Dec 2003
Posts: 17
Stumble this Post!
Apologise for being so vague

I'l try explain again - fully

I have to write a script that checks a file example - file1

in this file there is a line which looks like

291220032912200329122003

from this i have to make the script check that the date in the middle is the current date.

i.e 291220032812200329122003

this would not be current date therefore i have to raise an alert(which im fine with) to bring this to our attention.

This is my first attempt at writing a script so any help is really appreciated
Is this any clearer?

Thanks

Last edited by vcardo10; 12-29-2003 at 05:04 AM.
  #7 (permalink)  
Old 12-29-2003
google's Avatar
Moderator
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Stumble this Post!
OK, from what you stated, the script should check a string of 3 dates, and make sure that the date in the middle is the current date ( i.e. equal to todays date).

Will the date format always be: ddmmyyyy ?
When the day value or the month value is less than 10, will the format still be ddmmyyyy (i.e 01102003 - have a leading zero?)

If so, then the code I posted should work.
Google The UNIX and Linux Forums
Closed Thread

Tags
autosys

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:37 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0