generate rows from date.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting generate rows from date.
# 8  
Old 08-22-2007
Quote:
Originally Posted by ahmedwaseem2000
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
    }
}

i have ran this is the output ,sorry for truble. it is not incrementing and not printing propely.

$> awk -f myfiletest2.awk mydtfile.txt
1111 1999-01-01 2010-01-01
111112010-01-01
2222 2004-01-01 2040-01-01
222212040-01-01
# 9  
Old 08-22-2007
Quote:
Originally Posted by GrepMe
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
works fine here on Solaris' "nawk". What's your OS? Do you have 'gawk'?
# 10  
Old 08-22-2007
My os is AIX

Quote:
Originally Posted by vgersh99
works fine here on Solaris' "nawk". What's your OS? Do you have 'gawk'?
Thanks for your time.

My os is AIX
# 11  
Old 08-22-2007
I have tested with nawk as well on my OS aix.

Quote:
Originally Posted by GrepMe
Thanks for your time.

My os is AIX
I have tested with nawk as well on my OS aix ,it is printing only year.
# 12  
Old 08-22-2007
What version of AIX?
You didn't say if you had gawk or not AND/OR if you had 'nawk'.
I don't have AIX handy at the moment - so I cannot test.
According to AWK Compatibility List, AIX 5.3 has multiple 'awk-s' installed by default. You could try any one of them:
Quote:
Originally Posted by AIX 5.3
/bin/awk /bin/gawk /bin/nawk /usr/bin/awk /usr/bin/gawk /usr/bin/nawk
# 13  
Old 08-22-2007
sorry about the snafu - somhow it worked perfectly with gawk, but not with 'nawk'.
here's the modified script:
Code:
BEGIN {
    SEPdate="[ -]"
}
{
    n=split($0, tmpA, SEPdate)
    yStart=tmpA[2]
    yEnd=tmpA[n-2]
    for(i=yStart-1; i<yEnd;i++) {
        sub(i, i+1, $2)
        print
    }
}

# 14  
Old 08-22-2007
This code is working fine:

Code:
echo "1111 1999-01-01 2010-01-01" | awk '{

LowerYear=substr($2, 1, 4) 
RestDate=substr($2, 5, 6)
UpperYear=substr($3, 1, 4)
for(i=LowerYear; i<=UpperYear; i++) {
print $1 " "i RestDate " " $3 
    }
}'


Quote:
1111 1999-01-01 2010-01-01
1111 2000-01-01 2010-01-01
1111 2001-01-01 2010-01-01
1111 2002-01-01 2010-01-01
1111 2003-01-01 2010-01-01
1111 2004-01-01 2010-01-01
1111 2005-01-01 2010-01-01
1111 2006-01-01 2010-01-01
1111 2007-01-01 2010-01-01
1111 2008-01-01 2010-01-01
1111 2009-01-01 2010-01-01
1111 2010-01-01 2010-01-01
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