I have n files, like:
file1:
1aaa 2eee Test XXX Hanna Lars
file2:
1fff 2ffffd 3zzz Test XXX Mike Charly
You can do it with bash ( eg for 1 file)
bash
t=0 while read -r line do [[ $line =~ Test.*XXX ]] && t="1" case "$t" in 1) echo "$line";; esac done < file > tempo && mv tempo file
Use a for loop as necessary to go through all the files
for