【问题标题】:Bash Shell Commands with options带有选项的 Bash Shell 命令
【发布时间】:2019-10-11 12:29:59
【问题描述】:

我在使用 shell 将 translate 命令传送到字数统计命令时遇到问题。使用 Debian 9 Linux 发行版。

我需要从 /etc 目录中的 passwd 文件中删除冒号,并将结果通过管道传输到“字数统计”或 wc -w。我已经阅读了手册页,谷歌搜索并尝试了 youtube 视频,但找不到任何可以为我指明正确方向的内容。我尝试过的事情包括:

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

管道命令应该删除冒号,用空格替换它们,并更改字数/“wc”命令输出。

在使用 translate 和管道到 wc 之前,passwd 的字数等于 37 行、60 个字和 2054 个字节。我相信删除冒号后这个数字应该会增加。

【问题讨论】:

标签: linux shell command pipe command-line-arguments


【解决方案1】:

您必须先将文件内容发送至tr

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

或者cat,即使是useless use of cat

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

【讨论】:

  • 注意:这是useless use of cat
  • 谢谢!我没有想到您必须将其重定向到文件。尝试学习命令行时仍在爬行。
【解决方案2】:

你的意思是这样的?

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

【讨论】:

  • 谢谢你,这也很有效,直到我看到回复,我才知道你可以给这只猫剥皮多少种方法!
猜你喜欢
  • 1970-01-01
  • 2012-11-11
  • 2011-08-06
  • 1970-01-01
  • 1970-01-01
  • 2014-05-28
  • 1970-01-01
  • 2017-11-22
  • 1970-01-01
相关资源
最近更新 更多