Hi ,
I was trying to find files of a particular date and did that but then I also wanted to format a field based on some condition so had put another if else in awk.
Now it is getting the files of particular date or also the files which are matching that if else condition.
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"
}
(substr($0,12,8)==DATE)
{
if(substr($0,5,6)=="ABCR01")
{IN=1}
else
{IN=2}
}
{
clef = "2-PARSING_ERROR;" DATE ";" DATE_LOG ";"
substr ( $0, 12, 8) ";" substr ( $0, 5, 6 ) ";"IN";NS;NS;" $3
tab[clef]++
}
END {
for (clef in tab)
{
print tab[clef],clef
}
}
'
Now its giving returning the output if the file is of date "DATE" or if the files has substring matching ABCR01..
My motive is to find the files matching the date and to populate "IN" based on the condition.
Also, if i don't want to find files based on date then how to put the if else mechanism so that it doesnot select files for ABCR01 but populate IN as expected.
Please help
Regards
Abhinav
---------- Post updated at 02:10 PM ---------- Previous update was at 12:44 PM ----------
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"
}
(substr($0,12,8)==DATE)
{
clef = "2-PARSING_ERROR;" DATE ";" DATE_LOG ";"
substr ( $0, 12, 8) ";" substr ( $0, 5, 6 ) ";"IN";NS;NS;" $3
tab[clef]++
}
END {
for (clef in tab)
{
print tab[clef],clef
}
}
' | awk -F";"
'BEGIN {OFS=";"}
{if(substr($0,5,6)=="SMSR01")
{IN=1}
else
{IN=2}}
{ print $1,$2,$3,$4,$5,IN,"ALL","N/A",$NF}'
Solved my query like this.
Regards
Abhinav