tags:

views:

113

answers:

3

How do I redirect the output of a sed command as input to a tr command?

+5  A: 

use pipe line "|"

sed ... | tr -d '...'

sza
A: 

Looking at your comment, you say that the output of your sed command is on multiple lines. If it truly is on multiple lines, and not a wrap around, you could use a for loop

for i in $(sed ".."); do tr "$i"; done 
Ryan
That's not necessary, `tr` can handle multiline input. And you're feeding the output of `sed` as *instructions* to `tr`, but with no *input*. And, in general, using for that way can be a problem because spaces are delimiters. It would be better to use a `while read` loop. Something like `sed 's/foo/bar/' file | while read -r line; do echo "$line" | tr a B ; done` would *work* but the loop is unnecessary unless you were doing some other processing inside it.
Dennis Williamson
+1  A: 

You don't need tr. The y map predicate can do transliteration from within sed.

Ignacio Vazquez-Abrams
one difference is tr has other options as well. but yes, if its simple transliteration, the 'y' predicate of sed is sufficient
ghostdog74