Selecting the middle date!


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Selecting the middle date!
# 1  
Old 12-28-2003
Error 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
# 2  
Old 12-28-2003
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  
Old 12-29-2003
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.
# 4  
Old 12-29-2003
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  
Old 12-29-2003
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 11:46 PM..
# 6  
Old 12-29-2003
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 09:04 AM..
# 7  
Old 12-29-2003
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Selecting the file of latest Date

Hi Folks, I have one query that there is a folder in which daily several logs files are getting created , I reached to that location through putty but what I observer that 10 files of different date are been created with same name , what I need to see is the latest file ...let say the location is ... (5 Replies)
Discussion started by: KAREENA18
5 Replies

2. UNIX for Dummies Questions & Answers

How to separate First,Middle and Last Name from Full name

How to separate First,Middle and Last Name from Full Name? For Example: I/O :- 1) Ashok Kumar Requied Output: First Name:Ashok Middle Name: Last Name:Kumar I/O :- 2) Ashok K Kumar Requied Output: First Name:Ashok Middle Name:K Last Name:Kumar I/O :- 3) Ashok K R Kumar Requied Output:... (1 Reply)
Discussion started by: AhmedLakadkutta
1 Replies

3. UNIX for Dummies Questions & Answers

Removing duplicate rows & selecting only latest date

Gurus, From a file I need to remove duplicate rows based on the first column data but also we need to consider a date column where we need to keep the latest date (13th column). Ex: Input File: Output File: I know how to take out the duplicates but I couldn't figure out... (5 Replies)
Discussion started by: shash
5 Replies

4. Programming

selecting values of date

In a table, date is stored in a column as "2011-01-4". If I write query to get the dates > "2011-01-06" , then the date "2011-01-4" is also listed. The date stored in the column is a varchar datatype. So how can I make a query to not display the date "2011-01-4" ? Is there any solution ? Thank... (4 Replies)
Discussion started by: gameboy87
4 Replies

5. Shell Programming and Scripting

PERL - Selecting specific files based on 'date stamp' values

Hi, I've list of files in a directory, which have date stamp value in their names. ex: abc_data_20071102.csv, abc_data_20091221.csv, abc_data_20100110.csv, abc_data_20100222.csv, abc_data_20080620.csv,... etc., I need to select and process only files, within the given date... (4 Replies)
Discussion started by: ganapati
4 Replies

6. Shell Programming and Scripting

add a word in the middle

I have a file where in I need to add gctunit1/gtdivcompebb1/ after the = sign for example: gtfix31/gctunit_gtdivcompebb1/csclkswcompbypassstepgnnnh = gctunit1/gtdivcompebb1/csclkswcompbypassstepgnnnh (3 Replies)
Discussion started by: pitagi
3 Replies

7. Shell Programming and Scripting

Selecting files between a user inputed date range

Hi all! I'm working on a KSH script to select files between a user inputed date range (stored in a variable) and then move them and unzip them. I'm stuck at how to get the files between the user inputed date range selected. Any help would be greatly appreciated! The files are as such: ... (6 Replies)
Discussion started by: kelldan
6 Replies

8. Shell Programming and Scripting

How to process from middle of a file?

Hi There. I have a file like this . a nnnn sds b ssss fdefd c sdfd dsfd sdfds ... ... Summary t1 t2 t3 t4 s1 s2 s3 s4 f1 f2 f3 f4 .. How to use awk to begin process this file from the line that contains "Summary"? Thanks! louis (12 Replies)
Discussion started by: javacore
12 Replies

9. Shell Programming and Scripting

change RS in the middle

in AWK, how can I change the RS (record separator) in the middle of awk command. for example: gawk 'NR==FNR { key++;next }; RS="?"; $1 in key' file1 file2 in above, I put RS="?" in the middle to change the value of RS to "?" right after the file1 has been processed. when it begins to... (2 Replies)
Discussion started by: fredao
2 Replies

10. Shell Programming and Scripting

How to 'sed' the middle line?

Hi, If I have 90 lines and I want to print the 45th line, is there a quick sed command for this? thx. (7 Replies)
Discussion started by: g_jumpin
7 Replies
Login or Register to Ask a Question