The redis
data in the demo file aaa
is:
million:relive:2270371,18,1
million:relive:user:49976159,27:8,340|2018-01-26 20:25:00
million:relive:stage:22,6,1
The result is to add an additional column based on the thrid part of the redis
key :
uid,million:relive:2270371,18,1
user,million:relive:user:49976159,27:8,340
stage,million:relive:stage:22,6,1
I can generate the first column using:
awk -F":" '{print $3}' aaa | awk '{if($0 ~ /^[0-9,]+?$/) print "uid"; else print $0}'
And the second part:
awk -F"|" '{print $1}' aaa
How to combine the two parts and is it possible to make them in one sentence?
$ awk -F':' '{sub(/\|.*/,"");print ($3~/^[0-9]+,/?"uid":$3)","$0}' aaa
uid,million:relive:2270371,18,1
user,million:relive:user:49976159,27:8,340
stage,million:relive:stage:22,6,1
The above one-liner should help you. It first removed the |......
part, then add the key depending on the $3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With