How to pipe in the result of another UNIX command
Asked Answered
A

2

7

Right now I'm using another text file to store the result of one UNIX command and then using that file to run another command, like so:

tr -d "[,|.]" < text > temporary.txt
tr "[A-Z]" "[a-z]" < temporary.txt > result.txt

How do I combine these two into a single line so that I don't have to use a temporary file? The following does not work:

(tr "[A-Z]" "[a-z]" < (tr -d "[,|.]" < text)) > result.txt

I know how to use && but that still requires the use of a temporary holder file.

Possible duplicate: Bash: how to pipe each result of one command to another

Astrakhan answered 31/8, 2012 at 1:14 Comment(0)
E
7

Pipes are your friend:-

cat text | tr -d "[,|.]" | tr "[A-Z]" "[a-z]" >result.txt
Egomania answered 31/8, 2012 at 1:28 Comment(0)
P
3

Try:

  1. tr -d "[,|.]" < text | tr "[A-Z]" "[a-z]" > result.txt
  2. cat text | tr -d "[,|.]" | tr "[A-Z]" "[a-z]" > result.txt

Both commands do the same job.

What pipe(designated by |) does, is just redirects output of one command to the input of another. So, for example, in foo | bar the output of foo gets redirected into input of bar.

Phytogeography answered 31/8, 2012 at 1:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.