Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash conditional sum

# Basic syntax:
awk '{ if ( condition ) { sum += $field; }} END { print sum }' your_file
# Where:
#	- $field is the field to sum if the condition is true

# Example usage:
# Sum all fields of column 5 in your_file that don't have "*" in field 3
awk '{ if ($3 != "*" ) { sum += $5; }} END { print sum }' your_file
# Note, explicitly setting your_file's field delimiter with 
#	"BEGIN { FS="<input_delimiter>" };" might be needed for non-standard 
#	delimiters
Comment

PREVIOUS NEXT
Code Example
Shell :: yarn global package not found 
Shell :: git update on linux 
Shell :: extract tar.xz ubuntu 
Shell :: firebase hosting did not update 
Shell :: install kubectx 
Shell :: install virtual environment ubuntu 
Shell :: how to uninstall neovim on linux 
Shell :: linux how to kill any process on port 
Shell :: conda install mmcv 
Shell :: ubuntu check computer architecture 
Shell :: how to stop docker service windows 
Shell :: how to push code to github forcefully 
Shell :: compress a folder linux zip 
Shell :: xlsx Module ../../xlsx/types has no exported member IProperties. Did you mean Properties? 
Shell :: docker compose down 
Shell :: awk get second column from command output 
Shell :: command to open linux home folder in windows 
Shell :: how to remove git history for a file 
Shell :: check hostname linux 
Shell :: hash sum mismatch ubuntu 
Shell :: bash view the contents of a sqfs file 
Shell :: linux command print hostname 
Shell :: reconnaissance in cyber security 
Shell :: linux find text in pdf file 
Shell :: Ubuntu check free space by 5 ways 
Shell :: react-devtools agent got no connection 
Shell :: classic doom for linux ubuntu 
Shell :: cannot find module time stamp 
Shell :: find all the git repos recursivelty 
Shell :: use python shell with git bash 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =