How do I redirect the output of a sed command as input to a tr command?
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
2010-04-13 04:55:53
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
2010-04-13 08:39:26
+1
A:
You don't need tr
. The y
map predicate can do transliteration from within sed.
Ignacio Vazquez-Abrams
2010-04-13 04:57:52
one difference is tr has other options as well. but yes, if its simple transliteration, the 'y' predicate of sed is sufficient
ghostdog74
2010-04-13 05:13:22