I use the following as an example. I find myself always doing this and I believe my scripts would run much faster if I put the sed results into a place in memory rather than writing to files. Again, its not about sed, its about redirecting to a place in memory rather than an external file.
#!/bin/bash
sed -r 's/\s+/ /g' vts.txt > vts2
while read x y z
do
echo $y
done < vts2
Now the following obviously doesnt work, I provide it for illustration
#!/bin/bash
vts2=`sed -r 's/\s+/ /g' vts.txt`
while read x y z
do
echo $y
done < $vts2
I hoping this is a vastly simplified example. Did you know that the read built-in will automatically chomp multiple whitespace charactersso you could have simply done:
while read x y z
do
echo $y
done < vts.txt
But, assuming you are doing some sort of more complex sed or grep the read loop: pipes are the way to go.
Of course if you find yourself doing sed ... | grep ... | sed ... | kitchen-sink it's probably time to consider using a more powerfull text processing command, like awk script.
It seems like one better sed script would suffice ( add 's/^[^ ]+ \(.*\) [^ ]+$/\1/' ), or a better bash script extending the set in $IFS and using just 'while read'.