且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

搜索文本文件的脚本

更新时间:2023-12-05 20:31:16




我无法明确需要


查找路径名-name * .txt -exec ls -l {} \;


I cant get ur need clearly

find pathname -name *.txt -exec ls -l {} \;


find pathname -name' '* .txt''
find pathname -name ''*.txt''


感谢您的帮助,以下是我的要求:




到期第7天(星期一):



创建一个脚本,搜索包含给定关键字出现次数最多的文本文件。例如,如果我想搜索if语句的大部分用法的脚本,我会执行:



find_most_relevant.sh / home / yevgeniy / myscripts如果



脚本find_most_relevant.sh应该有两个参数。第一个是文本文件所在的目录(递归搜索对于此分配是可选的)。第二个参数是关键字。脚本的输出应该说明:



没有带有单词< keyword>的文件在目录< directory-name>中找到。








file< filename>:找到X出现的单词< keyword>



(对于最多出现关键字的文件)



提示1:如果您愿意,可以使用命令grep -o key filename | wc -l计算单个文件中出现的次数。



提示2:我的完整信用脚本版本只有22行。你可以或多或少 - 只是不要以为这个任务要求任何非常复杂的东西。
Thanks for your assistance below is what I am being asked:



Due Day 7 (Monday):



Create a script that searches for a text file with most occurrences of a given keyword. For instance, if I would like to search for a script with most usages of if statement, I would execute:



find_most_relevant.sh /home/yevgeniy/myscripts if



The script find_most_relevant.sh should take two arguments. The first one is the directory where text files are located (recursive search is optional for this assignment). The second argument is a keyword. The output of the script should either state:



No file with word <keyword> found in the directory <directory-name>.



Or



file <filename>: found X occurrences of word <keyword>



(for the file with most occurrences of keyword only)



Hint 1: If you would like, you can use command grep -o key filename | wc -l to count number of occurrences in a single file.



Hint 2: My version of full-credit script is only 22 lines long. Yours can be either more or less than that - just don''t assume that this assignment asks for anything terribly complicated.