Skip to content

Instantly share code, notes, and snippets.

@N1v0k
Created December 11, 2019 14:23
Show Gist options
  • Save N1v0k/7d1f5ccd7dc1fdddabb52e48857a933c to your computer and use it in GitHub Desktop.
Save N1v0k/7d1f5ccd7dc1fdddabb52e48857a933c to your computer and use it in GitHub Desktop.
Reads a file line-by-line and applies regex with two groups and checks if left string is present in right string
#!/bin/bash
# Reads a file line-by-line and applies regex with two groups and checks if left string is present in right string
regex="([0-9]{10})#PHVN(.*)"
while IFS="" read -r p || [ -n "$p" ]
do
line=$(printf '%s\n' "$p")
if [[ $line =~ $regex ]]
then
needle="${BASH_REMATCH[1]}"
hay="${BASH_REMATCH[2]}"
if [[ ! "$hay" =~ "$needle" ]]; then
echo "$line"
fi
fi
done < "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment