Skip to content

Instantly share code, notes, and snippets.

@jacopotarantino
Created November 21, 2015 17:44
Show Gist options
  • Save jacopotarantino/2a6e3cb55292bcfd6108 to your computer and use it in GitHub Desktop.
Save jacopotarantino/2a6e3cb55292bcfd6108 to your computer and use it in GitHub Desktop.
Looping over files to find a particular line in those files
#! /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