generate rows from date.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting generate rows from date.
# 1  
Old 08-21-2007
generate rows from date.

Hi

I have file like below has many rows with different dates and ids.


ID FIRST_DT SEC_DT
111 2005-10-02 2010-10-01
222 2007-11-01 2040-09-13

I need to generate rows first_dt increment + 1 year until the SEC_DT year matches ,ID and sec_dt stays same ,here is the example below.

ID FIRST_DT SEC_DT

111 2005-10-02 2010-10-01
111 2006-10-02 2010-10-01
111 2007-10-02 2010-10-01
111 2008-10-02 2010-10-01
111 2009-10-02 2010-10-01
111 2010-10-02 2010-10-01

can you please help with this.

Thank you for your time.
# 2  
Old 08-21-2007
nawk -f grepMe.awk myFile

grepMe.awk:
Code:
BEGIN {
    SEPdate="[ -]"
}
{
    n=split($0, tmpA, SEPdate)
    yStart=tmpA[2]
    yEnd=tmpA[n-2]
    for(i=yStart; i<=yEnd;i++) {
        sub($2, i, $2)
        print
    }
}

# 3  
Old 08-22-2007
Thanks for your time ,it is just printing the year only

Hi

i have tested the script it is just printing the year YYYY only, can you help print month and date as well.

awk -f script.awk input_file.txt

here is the output from my testing.

1111 1999 2010-01-01
1111 2000 2010-01-01
1111 2001 2010-01-01
1111 2002 2010-01-01

thanks in advance.
Pimmit
# 4  
Old 08-22-2007
Not tested but try this:

Code:
awk  '{

split ($2, LowerDate, "-")
split ($3, UpperDate, "-")
print 
 for(i=LowerDate[0]; i<=UpperDate[0]; i++) {

NewDate= sub( LowerDate[0], i, $2 )
print $1 NewDate $3
    }
}' Filename


Last edited by ahmedwaseem2000; 08-22-2007 at 10:12 AM..
# 5  
Old 08-22-2007
some error message

it did n't run it says syntex error with script.

what is the filename at end of the script.

awk -f script.awk input_file.txt
# 6  
Old 08-22-2007
File name is the absolute path of the file that has data in it.
# 7  
Old 08-22-2007
or try this code:

Code:
{

split ($2, LowerDate, "-")
split ($3, UpperDate, "-")
print 
 for(i=LowerDate[0]; i<=UpperDate[0]; i++) {

NewDate= sub( LowerDate[0], i, $2 )
print $1 NewDate $3
    }
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generate sum of a particular column date wise

Hi All, I have a file with below content 01/22/2014,23:43:00,1742.8, 01/22/2014,23:43:00,1742.8, 01/22/2014,23:44:00,1749.06666666667, 01/25/2014,23:45:00,2046.45, 01/25/2014,23:43:00,1742.8, 01/25/2014,23:44:00,1749.06666666667, 01/25/2014,23:45:00,2046.45, 01/25/2014,23:43:00,1742.8,... (4 Replies)
Discussion started by: villain41
4 Replies

2. Shell Programming and Scripting

UNIX script generate report grouped on date

Dear Team, I am try n gerrating a report by writing a shell script, the content of the report should be aggrigated based on date value exist in the content of the file. initially the file is zip format My file content is in below format 031627787 034626800357002013050613310400000013500 CLT01... (1 Reply)
Discussion started by: balram0179
1 Replies

3. UNIX for Dummies Questions & Answers

Compare date and generate email

i have a list of dates in two columns in the format of "+%Y%m%d", and i would like to take the last line and compare it to system date in the same format. if it doesn't exist the file has to send an email on for example 25th. please help.:confused: (1 Reply)
Discussion started by: sadek
1 Replies

4. Shell Programming and Scripting

removing rows from text file older than certain date

Hi I need a way of removing rows from a txt file that are older than 30 days from today, going by the date in column 2, below is an example from my file. I have tried awk but don't have enough knowledge. I would really appreciate some help. 41982,15/07/2010,H833AB/0,JZ,288... (6 Replies)
Discussion started by: firefox2k2
6 Replies

5. Shell Programming and Scripting

Generate last hour date in YYYYmmddHH

can some one show me how to generate last hour of date for example: 2012010100 -> 2011123123 // check first date of a new year 2008030100 -> 2008022923 // check leap year as well And also no perl code is restricted. This is what i am facing issue now, can someone provides help to me. (4 Replies)
Discussion started by: alvin0618
4 Replies

6. Shell Programming and Scripting

Generate quarter dates with begin date and end date

Hi All, I am trying to generate quarter dates with user giving input as begin date and end date. Example: Input by user: begin_date = "2009-01-01" end_date = 2010-04-30" required output: 2009-01-01 2009-03-31 09Q01 2009-04-01 2009-06-30 09Q02 . . till 2010-01-01 2010-03-31 10Q01 ... (9 Replies)
Discussion started by: sol_nov
9 Replies

7. Shell Programming and Scripting

Help to generate date from day of the year

Hi I want to convert the day of the year(yyyyddd) to date in mmddyy format Example: input is 2005029 --------> 29th day of 2005 I have to get the output as 01292005 ---> jan 29th 2005 I've to do this in K-Shell There were threads that dealt with coverting date to day of the year but I... (3 Replies)
Discussion started by: sudhamayeev
3 Replies

8. Shell Programming and Scripting

Removing rows from a file based on date comparison

I have a '|' delimited file and want to remove all the records from the file if the date is greater than a year from sysdate. The layout of the file is as below - xxxxxxxxxxxxxx|yyyyyy|zzzzzz|2009-12-27-00:00| 000000000|N xxxxxxxxxxxxxx|yyyyyy|zzzzzz|2010-01-03-00:00| 000000000|N... (4 Replies)
Discussion started by: Max_2503
4 Replies

9. Shell Programming and Scripting

Requesting an AWK code to generate averaged rows in a column

Hello, I request your kind help in solving this problem... I have a file with two columns and "n" number of rows. For the first column, it won't be change. For the second column, I want to take the average of the first three rows. Then assign the averaged value to the first three rows. This... (8 Replies)
Discussion started by: solracq
8 Replies

10. UNIX for Dummies Questions & Answers

Subtract date & time in diferent rows

Hi Friends :) I have a long file having fields in the form : Field1 yy/mm/dd hh:mm:ss Duration(Sec) line 1) 123123 05/11/30 12:12:56 145 line 2) 145235 05/11/30 12:15:15 30 line 3) 145264 05/11/30 13:14:56 178 . . I want to subtract yy/dd/dd hh:mm:ss in line (2) from yy/mm/dd hh:mm:ss in... (1 Reply)
Discussion started by: vanand420
1 Replies
Login or Register to Ask a Question