There is nothing really wrong with your grep and cut command. You could make it more robust by using "|30201|" as the search pattern. The issue then is dealing with the output.
Using bash:
#!/bin/bash # get the output as a bash array and add the elements nums=( $(grep "30201""|30201|" logfile.txt | cut -f6 -d "|") ) total=0 for i in ${!nums[@]} do total=$(($total+${nums[i]})) done echo $total