I'm writing a bash script to search the contents of a postfix log. To keep the script's output readable (since multiple lines from the log file need to be echo'ed) I am setting the IFS variable to an empty string so that the line breaks in my grep results are preserved. I am storing the results to a variable. Later in the script, I want to search the entire output as a single line of text. I am not sure if it is possible to make sed consider the results in this variable as a single line, so I am trying to simply remove all the line breaks using the following:
str1=${results//\n/}
However, it is not working. Does anyone have an idea what I'm doing wrong? The reason that I am trying to search the results as a single line is because I'm looping through all the lines in the search results, searching for a pattern that occurs multiple times. Each time a match is found, I do some further processing. However, if I just run the search results through sed, I get a list of every match. I'd like to be able to process each line separately if possible, but since I haven't been able to figure out how to do that I was trying to treat it as one long line and just parse through it from beginning to end.
If anyone has a better idea on how to do this, I'm open to suggestions. I'm intermediate when it comes to shell scripting, but by no means an expert like so much of you here.