【发布时间】:2021-07-17 15:44:44
【问题描述】:
这是我写的代码
echo "Positive count =" > file.txt | grep -o -i positive IMDB_Dataset.csv | wc -l >> file.txt
在 ubuntu 上,文件中的结果是
Positive count =
26188
我可以在同一行写成这样吗
Positive count = 26188
【问题讨论】:
-
你真的在 Ubuntu 上使用 CMD 吗?您可能实际上正在使用 Bash。顺便说一句,欢迎来到 Stack Overflow!如果需要提示,请查看tour 和How to Ask。
-
顺便说一句,
echo和grep之间的管道什么也不做。用换行符替换它。 -
也可以使用
printf "Positive count = %d\n" "$(grep -Foi positive IMDB_Dataset.csv | wc -l)" >> file.txt(除了文字字符串,我倾向于避免使用echo)