Skip to content

Instantly share code, notes, and snippets.

@tuananh
Created February 13, 2023 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuananh/8c981cdd22f9a7b993899e69f5ccf83d to your computer and use it in GitHub Desktop.
Save tuananh/8c981cdd22f9a7b993899e69f5ccf83d to your computer and use it in GitHub Desktop.
Bash: intersection of 2 lists
export LIST1=a b c d
export LIST2=b c d e f
INTERSECTION=($(comm -12 <(for X in "${LIST1[@]}"; do echo "${X}"; done|sort) <(for X in "${LIST2[@]}"; do echo "${X}"; done|sort)))
echo ${INTERSECTION[@]}
# b c d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment