Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #create example file
- for i in {1..20};do echo $((1 + $RANDOM % 99));done > list.txt
- #create example file, with floats
- for i in {1..20};do echo $((1 + $RANDOM % 99)).$((1 + $RANDOM % 99));done > list.txt
- #add using bash
- echo $(($(cat list.txt|tr "\n" "+"|sed 's/+$/\n/g')))
- #The above might cause issues with floats
- #it's better to use bc
- cat list.txt|tr "\n" "+"|sed 's/+$/\n/g'|bc
- #you can also use paste
- paste -s -d+ list.txt|bc
- #awk is another option
- cat list.txt| awk '{sum += $1} END {print sum}'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement