1

I want to store each single, complete, multiline result of a pcregrep into a variable for each iteration of a for loop.

Ex:

for a in $(pcregrep -Moh 'regex_that_spans_multiple_lines'); do
blah
blah
done

However, I'm not sure what IFS I should use which would properly recognize each separate pcregrep result so I can store it into the variable (one result per iteration).

I'm also open to hear other round-about means of accomplishing the goal (even if it doesn't involve IFS)

Here are some sample results that I'd be working with:

Result 1:

new PDO(
                                $connectionString,
                                $this->options['user'],
                                $this->options['password'],
                                $this->options['driverOptions']
                        );

Result 2:

mysqli_connect(
                        $this->options['host'], $this->options['user'], $this->options['password'], null, $this->options['port'], $this->options['socket']
                );

Thanks in advance

Nolan
  • 363
  • 2
  • 10
  • You will be better served storing the results in an *array* (or temp file). Bash input is *line-oriented*. `IFS` is the *Internal Field Separator*, it controls *word-splitting*, it has no effect on multi-line control. – David C. Rankin Nov 11 '15 at 05:01
  • I'm not sure this is possible. As far as I can tell, there's no special delimiter between results. The results are simply mixed together. – 4ae1e1 Nov 11 '15 at 07:54
  • What separates each multiline result from `pcregrep` in the output? – chepner Nov 11 '15 at 12:12

0 Answers0