Please help, need to create script to remove lines by date in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Please help, need to create script to remove lines by date in file
# 1  
Old 04-08-2014
Please help, need to create script to remove lines by date in file

Please Help (novice to PERL and SHELL scripting)…. Need to create a script which removes all lines in $filename = "cycle_calendar_ftp_out" older than current date – a variable which will be a number of days passed to script. For Ex it will look at the end date which is the last field (4) and compare it to current date (so for today it will take 08APR2014 – For Ex: 3 days) and remove all record which have a enddate less than 05APR2014) So I believe that the date will need to be converted to a number prior to comparing to current date. What I have thus far is a group of statements …
NOTE:
The file doesn’t have a header with column headings. This script will be scheduled to executed daily and will need to open file and remove lines and write to same file.

File layout: (end date is the last field)
Code:
GAHS*CGL-*01JAN2013000000*04JAN2013000000
GAHS*CGL-*13JAN2013000000*23JAN2013000000
GAHS*CGL-*31JAN2013000000*01FEB2013000000
GAHS*CGL-*01FEB2013000000*10FEB2013000000
GAHS*CGL-*21FEB2013000000*25FEB2013000000
GAHS*CGL-*26FEB2013000000*01MAR2013000000
GAHS*CGL-*01MAR2013000000*06MAR2013000000
GAHS*CGL-*14MAR2013000000*24MAR2013000000
GAHS*CGL-*24MAR2013000000*26MAR2013000000
GAHS*CGL-*02APR2013000000*03APR2013000000
GAHS*CGL-*03APR2013000000*05APR2013000000
GAHS*CGL-*05APR2013000000*14APR2013000000
GAHS*CGL-*14APR2013000000*16APR2013000000
GAHS*CGL-*25APR2013000000*26APR2013000000
GAHS*CGL-*26APR2013000000*01MAY2013000000

-----some of what I have thus far-------


Code:
use Time::Local;
open (SRC, "$model_dir/$filename") || die;
BEGIN {
FS = "*"
month["JAN"] = "01";month["FEB"] = "02";month["MAR"] = "03";
month["APR"] = "04";month["MAY"] = "05";month["JUN"] = "06";
month["JUL"] = "07";month["AUG"] = "08";month["SEP"] = "09";
month["OCT"] = "10";month["NOV"] = "11";month["DEC"] = "12";
}
 
{
day = substr($4,1,2) ;
mm = month[substr($4,3,3)];
year = substr($4,6,4) ;
 
printf "%s : %s / %s / %s\n", $4, mm, day, year ;
}


---------------------------------------------
Again any help is appreciated, Thank You for helping
Moderator's Comments:
Mod Comment Please use CODE tags (not FONT and SIZE tags) when displaying sample input, output, and code segments.

Last edited by Don Cragun; 04-08-2014 at 11:46 PM.. Reason: Get rid of FONT and SIZE tags; add CODE tags.
# 2  
Old 04-08-2014
Is this a homework assignment?
# 3  
Old 04-09-2014
No this is something I need to manage a file for my personal venture..

---------- Post updated 04-09-14 at 07:38 AM ---------- Previous update was 04-08-14 at 10:56 PM ----------

Does anyone have any suggestions?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Remove Comment Lines From Script/Input File

Hello, I have a SAS code that predominantly has comments line and the real code like below and i want to remove ONLY THE COMMENTS from the code in the single line or spanned across multiple lines. /******************************************************************** *** This Is a Comment... (4 Replies)
Discussion started by: arooonatr
4 Replies

2. Shell Programming and Scripting

Replacing Date in the file with Create date and timestamp

Hello, I have files that with a naming convention as shown below. Some of the files have dates in the file name and some of them don't have dates in the file name. imap-hp-import-20150917.txt imap-dell-gec-import-20150901.txt imap-cvs-import-20150915.txt imap-gec-import.txt... (8 Replies)
Discussion started by: Saanvi1
8 Replies

3. Shell Programming and Scripting

Script to remove lines within file

AIX. we have multiple files eg B1234567 B1235468 etc. (numbers change daily, only constant is the B prefix) trying to use using sed '/numberrange and length varies /d ' to remove a specific number range out of one of these files , we just don't know which one its in, as it could be in... (4 Replies)
Discussion started by: newbee2015
4 Replies

4. Shell Programming and Scripting

How do I take out(remove) the date part in the file name in a script?

Hi All, I need to create links between two directories. have multiple files in a specified location. Source Location ex: /opt/xdm/input/ Target Location ex: /opt/xdm input file names: 1. abc_app.aus.apac.yyyymmdd.dtd 2. abcd_app.aus.apac.yyyymmdd.dtd I need to build a code that reads... (1 Reply)
Discussion started by: kthri_82
1 Replies

5. Shell Programming and Scripting

Sum from successive lines following date header to create data for graphing connections

Hi, I have a log file created from a load balancer showing connections to each member of a two member pool with the following format (where first field is source IP, second field is load balanced IP address and third field is destination member. I need to plot a graph by date/time and number of... (5 Replies)
Discussion started by: shog63
5 Replies

6. Shell Programming and Scripting

shell script to remove all lines which exceeds a particular date & time

I have a text file which got 6th coloumn as date and 7th coloumn as time. The text contains data for last one week. I need to remove all the data whose date & time is after 03/08/2011 06:00:00 and save it on another file TEXT FILE ======== 6 dbclstr-b IXT_Web Memphis_Prod_SQL_Diff... (4 Replies)
Discussion started by: ajiwww
4 Replies

7. Shell Programming and Scripting

shell script to remove all lines from a file before a line starting with pattern

hi,, i hav a file with many lines.i need to remove all lines before a line begginning with a specific pattern from the file because these lines are not required. Can u help me out with either a perl script or shell script example:- if file initially contains lines: a b c d .1.2 d e f... (2 Replies)
Discussion started by: raksha.s
2 Replies

8. Shell Programming and Scripting

Shell script to remove duplicates lines in a file

Hi, I am writing a shell script that needs to remove duplicate lines within a file by category. example: section a a c b a section b a b a c I need to remove the duplicates within th category with out removing the duplicates from the 2 different sections (one of the a's in section... (1 Reply)
Discussion started by: RichElks
1 Replies

9. Shell Programming and Scripting

Command/Script to remove duplicate lines from the file?

Hello, Can anyone tell Command/Script to remove duplicate lines from the file? (2 Replies)
Discussion started by: Rahulpict
2 Replies

10. Shell Programming and Scripting

Need help to create a date script

So I need to create a shell script that can take as input a numeric day, month and year and output the day of the week for the input date. So let's say, I input "programname 19 10 2006" it should output Thursday... I tried messing around with the grep and awk commands, but I can't get it to... (6 Replies)
Discussion started by: mredwardlee
6 Replies
Login or Register to Ask a Question