sed '/\n/P;//!s/_\.[^ ("]*Text([^)]*)/\n&\n/;D' files... >results.txt
...would probably work. Run on your example data it prints:
_.Text("Hello World!")
_.Text("Foo")
_.ActionText("Bar")
All it does is attempt to enclose the first match on a line in \n
ewlines. Whether or not it succeeds it D
eletes up to the first \n
ewline in pattern space - which for a non-matching line completely removes it from output, but for a match deletes only up to the head of your pattern and the script starts again from the top. If a \n
ewline is matched in pattern space - which can only happen if a match was just found and then D
eleted - then sed
prints only up to the first occurring \n
ewline in pattern space - which is at the tail of your matched string. The s///
ubstitution is !
not attempted when there is a \n
ewline already in pattern space, so the D
elete command clears the already printed match and the cycle starts again from the tail of the last match on.
Depending on your sed
you may need to use a literal \n
ewline in place of the n
in the right-hand substitution field, though. But you should be able to do all of the file arguments at once - or, at least, very many at a time (depending on your ARGMAX limits). You can just shell glob for those, or maybe do...
find /path -name pattern -exec sed script_above {} + >>results.txt
...because sed
will treat all input files as a single stream.
grep
supports-o
, that would be the best candidate. – muru Feb 03 '15 at 14:15