Created
January 10, 2018 02:05
-
-
Save jclosure/592f2571aacbfd4eea5872fb97fe10a8 to your computer and use it in GitHub Desktop.
Bash read file for pattern matches and load into array
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
#!/bin/bash | |
FILE="some_file.txt" | |
PATTERN="some pattern" | |
RANGE=`grep -n $PATTERN $FILE | cut -d : -f 1` | |
while read -r line; do LINES+=("$line"); done <<<"$RANGE" | |
for line in "${LINES[@]}" | |
do | |
echo "-> $line" | |
done | |
FIRST=${LINES[0]} | |
LAST=${LINES[${#LINES[@]}-1]} | |
echo "first: $FIRST last: $LAST" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment