Created
November 21, 2015 17:44
-
-
Save jacopotarantino/2a6e3cb55292bcfd6108 to your computer and use it in GitHub Desktop.
Looping over files to find a particular line in those files
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 | |
# @description outputs lines and the files they came from to an arbitrary file | |
# @argument input {String} - regex looking for files in local directory | |
# @argument output {Filename} - where to echo found lines to | |
# @argument searchstring {String} - what to match for | |
# @example - ./search.sh '*.csv' outputfile.csv portuguese | |
echo $1 | |
for file in $1; do | |
echo "Examining $file" | |
cat $file | while read line; do | |
if [[ $line == *"$3"* ]]; then | |
echo $file >> $2 | |
echo $line >> $2 | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment