I have a file structure that looks like this:
- Folder1
- file1.feature
- file2.feature
- file3.feature
- Folder2
- file1.feature
- file2.feature
- ...etc.
The files are Behat feature files which look like this:
Scenario: I am filling out a form
Given I am logged in as User
And I fill in "Name" with "My name"
Then I fill in "Email" with "myemail@example.com"
I am trying to iterate over each file within the file structure to get matches on my regex:
/I fill in "[^"]+" with "([^"]+)"/gm
The regex looks for I fill in "x" with "y", and I would like to store the capture group "y" from each file where a line in the file matches the expression.
So far I can iterate through the folders and print out the file names in mt Bash script like so:
#!/bin/bash
cd behat/features
files="*/*.feature"
for f in $files
do
echo ${f}
done
I am trying to retrieve the capture group using Sed currently by doing this in my loop:
sed -r 's/^I fill in \"[^)]+\" with \"([^)]+)\"$/\1/'
But I fear that I am going down the wrong track, as this is returning all of the file content throughout all the files.