I have a log file which contain lots of line like below:2017-07-16 01:06:07 | 8801624874139 | http://192.168.5.1:2020/credit/purchase/4 | XpressLoan | {resultCode:0,resultMessage:OK,amount:100000,serviceFee:24400,totalOutstandingdebt:124400,msisdn:8801624874139}  2017-07-16 01:06:24 | 8801628666938 | http://192.168.5.1:2020/credit/purchase/5 | XpressLoan | {resultCode:0,resultMessage:OK,amount:50000,serviceFee:12180,totalOutstandingdebt:62180,msisdn:8801628666938}From the above log how can I get the amount value?Expected output:10000050000
How to extract specific text from a log file using linux terminal?
linux;awk;grep
Try this:$ awk -F\ '/amount/ {print $9}' file | sed 's/[:|,]//g'10000050000OR:$ sed 's/^.*amount\:\([0-9]*\),\.*$/\1/' file10000050000EDITYou can summarize the output of the first command if you pipe it again to awk like this example:$ awk -F\ '/amount/ {print $9}' file | sed 's/[:|,]//g' |\awk '{sum += $1} END {print sum}'150000