0

I'm having issues with piping the translate command into the word count command using the shell for an assignment. Using Debian 9 Linux distro.

I need to remove colons from the passwd file in the /etc directory and pipe the results into "word count" or wc -w. I have read the man pages, google searched and tried youtube videos, but could not find anything that would point me in the right direction. Things I have tried include:

tr -d ":" | wc -w /etc/passwd

tr -d [:punct:] | wc -w /etc/passwd

tr -- delete [:punct:] | wc -w /etc/passwd

tr -s [:punct:] [:space:] | wc -w /etc/passwd

tr -t [:] [" "] | wc -w /etc/passwd

The piped command is supposed to delete colons, replace them with spaces, and change the word count/"wc" commands output.

Before using translate and piping to wc, passwd's word count is equal to 37 lines, 60 words and 2054 bytes. I believe the number is supposed to increase when you remove the colons.

jww
  • 97,681
  • 90
  • 411
  • 885
  • Possible duplicate of [Piping and Redirection](https://stackoverflow.com/q/9553628/608639), [cat file | ... vs ... Precedence](https://stackoverflow.com/q/12942042/608639), etc. – jww May 24 '19 at 23:57

2 Answers2

0

You have to send the content of the file to tr first.

< /etc/passwd tr ":" " " | wc -w

Or with cat, even when it's a useless use of cat.

cat /etc/passwd | tr ":" " " | wc -w
Tony Stark
  • 2,318
  • 1
  • 22
  • 41
0

you mean something like this?

tr ":" " " < /etc/passwd | wc -w
UtLox
  • 3,744
  • 2
  • 10
  • 13