0

I'm trying to use the following command to extract a time period forthe current day date and grep for the specific message as you can see below:

awk -v date="$(date +%Y%m%d')" '$1="date" && $3>"180000" && $3<"192000"' /app/exploit/log/FILE_send.log | grep "End success file transfer /app/reception/FILENAME.dat to HOSTX"

But I'm having trouble to filter by the date column which is the first. Here's the output of the awk command when I remove the variable from the awk command and specify a date on $1=20190405:

1 - 180050 | INFO | FILE_SEND.sh | | FILENAME.dat | 1800498307000 | End success file transfer /app/reception/FILENAME.dat to HOSTX

Here is the line that log has:

20190405 - 180050 | INFO   | FILE_SEND.sh    |          | FILENAME.dat                    | 1800498307000 | End success file transfer /app/reception/FILENAME.dat to HOSTX

I can't see the reason for the column be replaced by 1. How can I filter the first column for the current day.

1

You can use the command:

awk -F'[-|]'  -v date="20190405" '$1 == date && $2>180000 && $2<192000' file_name | grep "End success file transfer /app/reception/FILENAME.dat to HOSTX"

The output of awk command will be:

 20190405 - 180050 | INFO   | FILE_SEND.sh    |          | FILENAME.dat                    | 1800498307000 | End success file transfer /app/reception/FILENAME.dat to HOSTX

With variable date use:

awk -F'[-|]'  -v date="$(date +%Y%m%d)" '$1 == date && $2>180000 && $2<192000' filename
  • Thanks for the reply but how it would be the variable done for current day I tried to use $(date +"%Y%m%d") and it didn't work. – anmoreira Apr 7 at 4:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.