awk-command-unix-choose-value-last-column-to-sum

รวมผลจำนวนเงิน โดยใช้ unix command “awk ‘{print $NF}’

## cut last column in text file by awk ‘{print $NF}’

06/04 NEW HAMPSHIRE INSURANCE CBANGKOK TH 07/04 367.00
06/04 ESSO-VPK CHAROENNAKORN(1)BANGKOK TH 08/04 600.00
07/04 BTS BANGKOK TH 08/04 450.00
09/04 SHABU HAVEN-C.PLAZA PINKLBANGKOK TH 09/04 998.00
13/04 40.00 U.S. DOLLAR ********* CONVERTED TO 44 GB 14/04 1,439.39
15/04 0.99 U.S. DOLLAR ********* CONVERTED TOITUNES.COM/BILL ITUNES.COM LU 16/04 35.70
15/04 2C2P *LIONAIR BANGKOK TH 16/04 1,400.00
19/04 True iService BANGKOK TH 20/04 1,485.16
20/04 ESSO-VPK CHAROENNAKORN(1)BANGKOK TH 22/04 800.00
20/04 2C2P *LIONAIR BANGKOK TH 22/04 1,200.00
21/04 571,019.00 RUPIAH ********* CONVERTED TOPT Trinusa Travelindo JAKARTA ID 23/04 1,560.85
23/04 IT CITY -L.PINKLAO 3 FL BANGKOK TH 23/04 439.00
23/04 PTTRM_CB BANBUNG 2 CHONBURI TH 23/04 500.00
26/04 ESSO-VPK CHAROENNAKORN(1)BANGKOK TH 27/04 500.00
30/04 True iService BANGKOK TH 01/05 1,427.25
01/05 ESSO-VPK CHAROENNAKORN(1)BANGKOK TH 03/05 500.00
02/05 2C2P *LIONAIR BANGKOK TH 03/05 1,100.00
03/05 TOPS PRANNOK BANGKOK TH 03/05 358.00
04/05 THE MALL 5 THONBURI DEPT.BANGKOK TH 05/05 291.00

#less text.txt | awk ‘{ print $NF}’
367.00
600.00
450.00
998.00
1,439.39
35.70
1,400.00
1,485.16
800.00
1,200.00
1,560.85
439.00
500.00
500.00
1,427.25
500.00
1,100.00
358.00
291.00

ถ้าต้องการ sum ค่าที่ออกมาทั้งหมด ก็เป็นดังนี้ ครับ
#less text.txt | awk ‘{ print $NF}’ | sed ‘s/,//g’ | bc | cut -d. -f1 | paste -sd+ | bc

Add A Comment

Your email address will not be published. Required fields are marked *