Created
May 4, 2020 13:25
-
-
Save nikto-b/7eed38728d5d0422833240fbd0271986 to your computer and use it in GitHub Desktop.
Bash one-liner that summs integers divisable by 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#it's important to have space after last integer | |
echo "1 2 3 4 5 " | tee a | sed 's/\s/\/3\n/g' | bc -l | sed 's/00//g' | sed 's/.$//g' | nl | grep -v '\.' | awk '{print $1}' > b; export A=$(cat a | sed 's/\s/\n/g'); export B=$(cat b); for i in $B; do echo -e "$A" | sed "${i}q;d" ; done | tr '\n' ' ' | rev | cut -c 2- | rev | sed 's/\s/+/g' | bc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment