I want to run an egrep
for several different patterns on a folder full of texts and output the results into corresponding folders. I'm also trying to make this neat and concise as this is a workflow I'll probably be using a lot.
So I have a folder full of texts called docs
and I want to find two different regex patterns (regex1 and regex2) and output them into docs/regex1
and docs/regex2
I would guess that something like this would work
mkdir {docs/regex1,docs/regex2}
for file in docs/*
do
egrep -o -f regex1 "$file" > regex1/"${file%.*}"_regex1.txt
egrep -o -f regex2 "$file" > regex2/"${file%.*}"_regex2.txt
done
This gives me the error:
regex1/docs/001_regex1.txt: No such file or directory
regex2/docs/001_regex2.txt: No such file or directory
For each file. How can I set the output do go into docs/regex1 instead of trying to go to regex1/docs?