Last active
March 14, 2018 21:36
-
-
Save renatoargh/567fa2fbed39bea381fef8ab8589331e to your computer and use it in GitHub Desktop.
Huge file comparision with redis (you better use linux `diff` instead)
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
| #! /bin/bash | |
| set -e | |
| set -u | |
| # redis-cli --raw FLUSHALL >/dev/null 2>%1; # uncomment to clear the database | |
| function hash () { | |
| printf %s "$1" | md5sum | cut -f1 -d' ' | |
| } | |
| # file 1 | |
| cat "$1" | while read -r line; do | |
| hash $line | { read hash; redis-cli --raw SET $hash 1 >/dev/null 2>&1; } | |
| done | |
| # file 2 | |
| cat "$2" | while read -r line; do | |
| RESULT=$(hash $line | { read hash; redis-cli --raw GET $hash; }) | |
| if [[ -z "$RESULT" ]]; then | |
| printf "%s\n" "$line" | |
| fi | |
| done | |
| # redis-cli --raw FLUSHALL >/dev/null 2>%1; # uncomment to clear the database |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.lifewire.com/subshells-in-bash-scripts-2200581