Selecting the middle date!


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Selecting the middle date!
# 8  
Old 12-30-2003
Smilie
Problem - ive just noticed ive written the date format wrongly - does this make a difference?

I should have written
200307072003070420030707

This is the format that the script will have to read. Can i change the script to yyyymmdd????


This is the format it will always take i.e with the 01, 02 ....

On the script you said would work does the data_file refer to the path name where this file is held. Do i replace data_file with the pathname?

Thanks
# 9  
Old 12-30-2003
You could very well change the sequence, just read the man page for *date*, it has more informations

date -u +%Y%m%d

data_file is the file in which you have your sequence of dates ie

20030707.........................

Regards
JK
# 10  
Old 12-30-2003
Smilie

Forgive me but ive never actually created a script
if i login to unix session and enter the script as it is

#!/bin/ksh
FILE_DATE=$(cut -c 9-15 ../../../data_file | head -1)
TODAYS_DATE=$(date +'%Y%m%d)

if [ ${FILE_DATE} != ${TODAYS_DATE} ]
then
echo "Dates Dont Match"
fi

then this will work. (Idont have to enter anything else?)
Do i just save it and then call it up with autosys?

Thanks - in advance
# 11  
Old 12-30-2003
Yes, this should work, but you should use a full path to the file name. I dont usually use relative paths. Also, if your date file only has 1 line in it then you can remove the | head -1 as this simply makes sure that the only 1 row is returned. Before adding it to the autosys queue, I would test it by running it! Make sure to give it executable permissions (chmod command).
By the way, data_file represents your file name. Change this to the name you call your file.

Also, this is very simple script, you may want to add some things to it such as a log file. The echo command "Dates dont match" will echo to standard out and will most certainly be missed by everyone. Redirect the output to a file, or have the script mail you a message if the dates do not match. There are many examples of mail scripts on these boards. Search them out. Good Luck
# 12  
Old 12-30-2003
Bug

Thanks for your help

I dont know about the chmod but i'l look it u in man n give it a go.

Thanks!
# 13  
Old 12-30-2003
this program assumes the following:
1) the pattern you are looking for is 8 charicters from the beginning of the line.

provided that condition is met this does what you need.

1) open a text editor and past the below code in it.
2) save the file and exit the editor
3) chmod 755 file_you_just_made
4) to execute the file type "./file_you_just_made FILE_TO_SEARCH DATE_TO_MATCH

5) if the date is NOT found you get an error on your screen
5a) if date IS found it exits quietly

Code:
#!/usr/bin/perl -w
#200307072003070420030707

use strict;

if ($#ARGV != 1) { print "Usage: ./script file_to_search date_to_search\n"; exit };
my $file=shift;
my $date=shift;

open (FILE, "$file") or die "Can not open the file ($!)";
my @data=<FILE>;
print "ERROR No proper date found\n" if (! grep /^........$date/, @data) ;

# 14  
Old 01-09-2004
Data

Hi there!!

Since discovered that this file has more than one line that it has to check!!

The format of the file looks like

MP 000000000000000000000000 200307072003070420030707000000000000000000
00000000.000000000000000.0000000000000000000000000000000000000000

MP 0000000000000000000000000 200307072003082920030707000000000000000000
00000000.000000000000000.0000000000000000000000000000000000000000

MP 000000000000000000000000 200305212003121720030521000000000000000000
00000000.00000000000000000000000000000000000000000000000000000000

There are somethin in the region of 9 of these sets of lines in a file. All of which should have the ssame date.
Didnt get the chance to try the first set of solutions unfortunatley so really not sure n how i would manage to get this to work.

Is it possible??
Can anyone help please??

To recap ive to get a script to check this file in particular the 200305212003121720030521 and to check the middle date in this = todays date and if not then raise an alert (which already exists so im assuming i just put in a pathname to the script)

Thanks in advance.

Last edited by vcardo10; 01-12-2004 at 05:56 AM..
 
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