Anthony Mellor
asked on
AWK: add from two digits (the month) within date string dd/mm/yyyy
In this snippet I am using an exel formula mid() to illustrate what I need to do, but do not know the AWK code for it.
where mid($10,4,2) is extracting and using the 12 from text entered like this 01/12/2005 for example
Based on this (in fact on previous code shown to me in here, but looked up as well)
"substr(s, a, b) : it returns b number of chars from string s, starting at position a. The parameter b is optional."
is it substr ? So should it be
Clearly not as I get this:
maybe newval needs opening and closing brackets..
testdate.csv
awk 'BEGIN {FS=","; OFS="->"} {newval=($1*12)+(mid($10,4,2); print $0,newval}' testdate.csv >out.csv
where mid($10,4,2) is extracting and using the 12 from text entered like this 01/12/2005 for example
Based on this (in fact on previous code shown to me in here, but looked up as well)
"substr(s, a, b) : it returns b number of chars from string s, starting at position a. The parameter b is optional."
is it substr ? So should it be
awk 'BEGIN {FS=","; OFS="->"} {newval=($1*12)+(substr($10,3,2); print $0,newval}' testdate.csv >out.csv
Clearly not as I get this:
MacPro:FinalProcess ADM$ awk 'BEGIN {FS=","; OFS="->"} {newval=($1*12)+(substr($10,3,2); print $0,newval}' testdate.txt >out.txt
awk: syntax error at source line 1
context is
BEGIN {FS=","; OFS="->"} >>> {newval=($1*12)+(substr($10,3,2); <<<
awk: illegal statement at source line 1
awk: illegal statement at source line 1
missing )
maybe newval needs opening and closing brackets..
testdate.csv
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER