echo $line | awk -F, "BEGIN {if(NF==10) && /'"${MONTH}"' '"${DAY}"' '"${TIMEH}:"'/,0 {print $10"-"$4} else {print $13"-"$4}}"
if the fields in the line is equal to 10, print the values of this specified fields "$10 and $4".
if the fields in the line is anything but 10, print the values of field "$13 and $4".
Yoda
2
Why is it inside BEGIN
block?
A BEGIN
rule is executed once only, before the first input record is read.
initially, this is the command i was using:
echo $line | awk -F, '(NF==10) && /'"${MONTH}"' '"${DAY}"' '"${TIMEH}:"'/,0 {print $10"-"$4}'
but i needed to include the "else" condition in there.
CarloM
4
So, why is it inside the BEGIN block?
You could have something like:
awk -F, '/'"${MONTH}"' '"${DAY}"' '"${TIMEH}:"'/,0 {if(NF==10) {print $10"-"$4} else {print $13"-"$4}}'
1 Like
RudiC
5
In the BEGIN section, no file is read yet, so NF is not defined. Try
echo $line | awk -F -v DateTime="${MONTH} ${DAY} ${TIMEH}" \
'match ($0, DateTime) {InRange=1}
InRange && NF==10 {print $10"-"$4; next}
InRange {print $13"-"$4}
'
1 Like
this did the trick. Thank you!!!!!!!!
---------- Post updated at 12:28 PM ---------- Previous update was at 12:24 PM ----------
this too, thanks so much!