2 calelin calelin 于 2017.09.02 05:45 提问

试写一个linux命令行,可以统计所有python程序中for出现的次数,并将结果输出到某个文件中

原题:
Write a command line that counts how many times the word 'for' appears in python files (files that end with .py) within your current directory. The resulting number should be placed in a file called 'result
下面是我写的命令,但是不知道如何修改能实现输出到某个文件中的功能
grep -o for *.py | wc -l

1个回答

yujiaao
yujiaao   2017.09.02 08:44
已采纳

重定向到文件就好了:

 grep -R -o for *.py | wc -l >abc.txt
Csdn user default icon
上传中...
上传图片
插入图片