Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date/month increment

Status
Not open for further replies.

ranjit

Technical User
Apr 14, 2000
131
GB
I have the below file and am trying to meet the below requirement

Input file:
(YEAR(CENTRAL_PROC_DATE)=2004 and MONTH(CENTRAL_PROC_DATE)=04 )
(YEAR(AUTH_DATE)=2004 and MONTH(AUTH_DATE)=12)

Requirement:
For MONTH's 01-11:
Increment MONTH by 1

For MONTH 12
Increment YEAR by 1 and change MONTH to 01

Desired output:
(YEAR(CENTRAL_PROC_DATE)=2004 and MONTH(CENTRAL_PROC_DATE)=05 )
(YEAR(AUTH_DATE)=2005 and MONTH(AUTH_DATE)=01)

Any ideas please?
 
Code:
[B]BEGIN[/B] [COLOR=#4444FF][B]{[/B][/color]
    [COLOR=#444444]# use field separators to slice the input line[/color]
    [B]FS[/B] = [COLOR=#008000]"[( =)]*"[/color];
[COLOR=#4444FF][B]}[/B][/color]

[COLOR=#4444FF][B]{[/B][/color]
    [COLOR=#444444]# $8 is the month and $4 is the year[/color]
    $8++
    [B]if[/B] [COLOR=#4444FF][B]([/B][/color]$8 > 12[COLOR=#4444FF][B])[/B][/color] [COLOR=#4444FF][B]{[/B][/color]
        $8=1
        $4++
    [COLOR=#4444FF][B]}[/B][/color]
    [COLOR=#a52a2a][B]printf[/B][/color] [COLOR=#008000]"(%s(%s)=%s %s %s(%s)=%02i)[COLOR=#77dd77]\n[/color]"[/color],
        $2, $3, $4, $5, $6, $7, $8
[COLOR=#4444FF][B]}[/B][/color]
 
Could somebody please explain how the FS works: FS = "[( =)]*"???
 
FS is a regular expression, man regexp for details, but in brief...

[tt][( =)] [/tt] means match any one of "(", space, "=" or ")"
[tt]* [/tt] means zero or more occurances.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top