搜索文本文件的脚本 [英] Script that searches for text file

查看:126
本文介绍了搜索文本文件的脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是UNIX新手。我需要一个脚本来搜索大多数给定关键字出现的文本文件。

I am very new to UNIX. I need a script that searches for a text file with most occurrences of a given keyword.

推荐答案




我无法明确需要


查找路径名-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.


这篇关于搜索文本文件的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆