我从《命令行的数据科学》一书中得到了一个脚本,像Jeroen Janssens这样
curl -s http://www.gutenberg.org/cache/epub/76/pg76.txt |
tr '[:upper:]' '[:lower:]' | grep -oE '\w+' | sort |
uniq -c | sort -nr | head -n 10
并将其保存为top-world-1.sh
在Ubuntu 15.10 64bit的终端上,我./top-words-1.sh
输入了一条命令,并得到了喜欢的输出
./top-words-1.sh: line 1: $'\r': command not found
./top-words-1.sh: line 2: $'\r': command not found
我一下子猜到那是由多行引起的,因此我删除了“ \ n”个地方,使之成为这样的句子
curl -s http://www.gutenberg.org/cache/epub/76/pg76.txt |tr '[:upper:]' '[:lower:]' | grep -oE '\w+' | sort |uniq -c | sort -nr | head -n 10
但是我得到了
: invalid number of lines
我对bash脚本编程完全陌生。你能给我任何建议吗?提前致谢
在下面的评论中,我有:
#!/bin/bash
在文件顶部添加并得到输出bash: ./top-words-1.sh: /bin/bash^M: bad interpreter: No such file or directory
我使用dos2unix
命令来解决我的问题。感谢@muru的评论。原因由@steeldriver解释
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句