有没有办法通过管道传输命令的输出并将其定向到stdout
?
例如,fortune
打印一个幸运饼干stdout
并将其通过管道传输到下一个命令:
$ fortune | tee >(?stdout?) | lolcat
"...Unix, MS-DOS, and Windows NT (also known as the Good, the Bad, and
the Ugly)."
(By Matt Welsh)
Run Code Online (Sandbox Code Playgroud) 我会假设下面的例子工作得很好。
$ which -a python python3 pip | xargs -I {} {} --version
No '{}' such file or folder
$ which -a python python3 pip | xargs -I _ _ --version
No '_' such file or folder
$ which -a python python3 pip | xargs -I py py --version
No 'py' such file or folder
Run Code Online (Sandbox Code Playgroud)
但是当我以交互方式运行它时,它们根本不起作用,它甚至不替换字符串。我在手册页中没有看到关于第一个位置的特殊情况的注释。为什么这不起作用?
$ which -a python python3 pip | xargs -I py -p eval py --version
eval ~/.pyenv/shims/python --version?...y
xargs: eval: No such file or directory …
Run Code Online (Sandbox Code Playgroud) 如何使用 sed 将换行符替换为任何其他字符?
\n\n I cannot conceive that anybody will \n require multiplications at the rate of \n 40,000 or even 4,000 per hour ... \n\n -- F. H. Wales (1936) \n
Run Code Online (Sandbox Code Playgroud)\n\nI cannot conceive that anybody will require multiplications at the rate of 40,000 or even 4,000 per hour ... -- F. H. Wales (1936)\n
Run Code Online (Sandbox Code Playgroud)\n\n我试过了:
\n\n> pbpaste | sed 's/\\n/ /g' \n
Run Code Online (Sandbox Code Playgroud)\n\n但它输出与输入相同的东西。我知道这是一个换行符,因为我已经检查过它并且cat -ev
它$
按预期打印。
还有什么更好的命令可以做到这一点? …
如何查找文件中每个单词的计数?
我想要文本管道或文档中每个单词的直方图。文档中将存在新行和空行。我把除了 之外的所有东西都脱光了[a-zA-Z]
。
> cat doc.txt
word second third
word really
> cat doc.txt | ... # then count occurrences of each word \
# and print in descending order separated by delimiter
word 2
really 1
second 1
third 1
Run Code Online (Sandbox Code Playgroud)
它需要具有一定的效率,因为文件是 1GB 文本,并且无法处理指数时间负载。
如何查找文件中每个单词的计数?
我想要文本管道或文档中每个单词的直方图。
我已经能够将文档拆分为单词列表;所以每个单词都换行。如果您可以直接从文本文档中获取它,那么那里的解决方案也很好。
> cat doc.txt
word
second
third
word
really
> cat doc.txt | ... # then count occurrences of each word \
and print in descending order separated by delimiter
word 2
really 1
second 1
third 1
Run Code Online (Sandbox Code Playgroud)
它需要具有一定的效率,因为文件是 1GB 文本,并且无法处理指数时间负载。