Can you help me solve this request?
The first field represents a JOBID and I need to get the last processed count of the individual JOBID, so I tried to make the AWK script for doing that which just shows me the last data of the last JOBID.
How can I get the last data of the each JOBID with AWK?
@ Input Data
259/logs/progress.log:2017-01-31 13:54:02/PROCESSED_COUNT/0
259/logs/progress.log:2017-01-31 13:55:12/PROCESSED_COUNT/4881000
259/logs/progress.log:2017-01-31 13:55:15/PROCESSED_COUNT/5000000
260/logs/progress.log:2017-01-31 13:54:43/PROCESSED_COUNT/0
258/logs/progress.log:2017-01-31 13:54:02/PROCESSED_COUNT/0
258/logs/progress.log:2017-01-31 13:54:12/PROCESSED_COUNT/1018216
258/logs/progress.log:2017-01-31 13:54:22/PROCESSED_COUNT/2045037
260/logs/progress.log:2017-01-31 13:54:53/PROCESSED_COUNT/343000
260/logs/progress.log:2017-01-31 13:55:03/PROCESSED_COUNT/751997
260/logs/progress.log:2017-01-31 13:56:43/PROCESSED_COUNT/4814880
260/logs/progress.log:2017-01-31 13:56:49/PROCESSED_COUNT/4999996
@ AWK
awk '/PROCESSED_COUNT/ {a=$0} END{if (a!="") print a}' test
@ Output
260/logs/progress.log:2017-01-31 13:56:49/PROCESSED_COUNT/4999996
@ Desired Output
259/logs/progress.log:2017-01-31 13:55:15/PROCESSED_COUNT/5000000
258/logs/progress.log:2017-01-31 13:54:22/PROCESSED_COUNT/2045037
260/logs/progress.log:2017-01-31 13:56:49/PROCESSED_COUNT/4999996
Answer
You can store the entries during scanning the file and print them at the end:
awk -F/ '{a[$1]=$0}END{for(i in a){print a[i]}}' a.txt
One thing: That would not preserve the order of the last appearance of each id.
No comments:
Post a Comment