Sum the third column with awk

Add up the values in column 3 of a file where fields are split by spaces.

awk '{sum += $3} END {print sum}' file.txt

tool
linux133 commands
tags
linux

More linux commands

  • sed -i 's/old-string/new-string/g' file.txt

    Replace every match of a string directly in the file.

  • sort file.txt | uniq -c | sort -rn | head -20

    Count how often each line repeats in a file and show the top 20.

  • lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT,UUID

    Show disks, partitions and loop devices as a tree with filesystem type, mount point and UUID.

  • blkid

    Print UUID, LABEL and TYPE for every block device.

  • mount -t ext4 /dev/sdb1 /mnt/data

    Mount an ext4 partition to /mnt/data.

all 133 linux commands