Skip to content

Instantly share code, notes, and snippets.

@nikto-b
Created May 4, 2020 13:25
Show Gist options
  • Save nikto-b/7eed38728d5d0422833240fbd0271986 to your computer and use it in GitHub Desktop.
Save nikto-b/7eed38728d5d0422833240fbd0271986 to your computer and use it in GitHub Desktop.
Bash one-liner that summs integers divisable by 3
#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