Skip to content

Instantly share code, notes, and snippets.

@Tmw
Last active August 29, 2023 20:47
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 Tmw/53b0d9e4ce24c277bf116b3ee65ab3f2 to your computer and use it in GitHub Desktop.
Save Tmw/53b0d9e4ce24c277bf116b3ee65ab3f2 to your computer and use it in GitHub Desktop.
Bash script to process lines combined from multiple files excluding the lines in another file
#!/usr/bin/env bash
FILES="fruits.txt veggies.txt"
EXCLUSION_FILE="nope-list.txt"
COMBINED=$(cat $FILES)
FOODS=$(grep -vx -f $EXCLUSION_FILE <(echo $COMBINED | tr ' ' '\n'))
TOTAL_FOODS=$(echo "$FOODS" | wc -l | awk '{print $1}')
CURRENT_FOOD=1
echo "about to eat $TOTAL_FOODS foods"
echo "---------------------------------"
while read food; do
echo "eating: $food [$CURRENT_FOOD/$TOTAL_FOODS]"
let "CURRENT_FOOD=CURRENT_FOOD + 1"
done < <(echo "$FOODS")
apple
banana
pineapple
kiwi
manderin
orange
melon
apple
kiwi
rubarb
carrots
potatoes
brussel-sprouts
rubarb
peas
bell-pepper
cucumber
broccoli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment