Last active
August 29, 2023 20:47
-
-
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
This file contains 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
#!/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") |
This file contains 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
apple | |
banana | |
pineapple | |
kiwi | |
manderin | |
orange | |
melon |
This file contains 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
apple | |
kiwi | |
rubarb |
This file contains 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
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