Hi,
I am using this awk command in my shell script :
find . -name "*" -ctime -6 | xargs cat | grep -E -v ^fileName\|^\([0-9]\) | awk -v DATE="${CURR_DATE}" -v DATE_LOG=$DATE_SYS 'BEGIN {FS=";";OFS=";";CONVFMT="%.9g";OFMT="%.9g"} {{clef="2-PARSING_ERROR;"DATE";"DATE_LOG";"substr($0,12,8)";"substr($0,5,6}";NS;NS;"$3 ; tab[clef]++;}} END {for (clef in tab) {print tab[clef],clef;}}'
it is throwing error :
awk: syntax error Context is:
>>> DATE";"DATE_LOG";"substr($0,12,8)";"substr($0,5,6} <<<
I am not getting what is the issue?
Regards
Abhinav
---------- Post updated at 09:18 PM ---------- Previous update was at 09:13 PM ----------
But when I run it like this :
find . -name "*" -ctime -6 | xargs cat | grep -E -v ^fileName\|^\([0-9]\) | awk -v DATE="${CURR_DATE}" -v DATE_LOG=$DATE_SYS 'BEGIN {FS=";";OFS=";";CONVFMT="%.9g";OFMT="%.9g"} {{clef="2-PARSING_ERROR;"DATE";"DATE_LOG";"substr($0,12,8)";substr($0,5,6};NS;NS;"$3"" ; tab[clef]++;}} END {for (clef in tab) {print tab[clef],clef;}}'
it runs fine but in the output substr($0,5,6} is printed as it is
I am not getting how to fix this.
Yoda
June 19, 2013, 12:52pm
2
Please note that it always helps to understand issues better if you properly intent your code.
I'm not sure what you are trying to achieve, but I made few corrections in your awk code. See if it helps:
find . -name "*" -ctime -6 | xargs cat | grep -E -v ^fileName\|^\([0-9]\) | awk -v DATE="${CURR_DATE}" -v DATE_LOG="$DATE_SYS" '
BEGIN {
FS = ";"
OFS = ";"
CONVFMT = "%.9g"
OFMT = "%.9g"
}
{
clef = "2-PARSING_ERROR;" DATE ";" DATE_LOG ";"
substr ( $0, 12, 8) ";" substr ( $0, 5, 6 ) ";NS;NS;" $3
tab[clef]++
}
END {
for (clef in tab)
{
print tab[clef],clef
}
}
'
Thanks for the reply yoda..
Sorry the code is not intented.. I will keep that in mind for future.
What I am trying to do is..
finding some files and using the contents of the file to create a line as in the post and then will redirect to a file.
I am using array to count number of records in a file.
I couldnot think of better idea for this..
Please guide..
Was there any syntax error in the post?
Yoda
June 19, 2013, 2:39pm
4
Yes, I noticed few syntax errors and corrected them, but I didn't test it.
Did you try running it? Are you getting the expected output?
If no, post a sample from input file and desired output.
A case for the eye doctor: the terminating bracket must be ) not }
substr($0,5,6)