一个在文本文件搜索指定字符串的程序
来源:互联网 发布:js 数组[ ]什么意思 编辑:程序博客网 时间:2024/05/22 10:23
用perl实现的.
print "input file:";
$file=<STDIN>;
chomp($file);
open (Hand,$file)||die "can not open file";
print "input the string to search:";
$str=<STDIN>;
chomp($str);
print "the result:/n";
$i=0;
while (<Hand>)
{
$i++;
while (/$str/g)
{
print "line".$i.": ".$_;
}
}
保存为search.pl
C:/>perl search.pl
input file:hello.txt
input the string to search: hello
the result:
line2: this is a hello test.
lien5: helloworld.
这个程序运行特别快.
print "input file:";
$file=<STDIN>;
chomp($file);
open (Hand,$file)||die "can not open file";
print "input the string to search:";
$str=<STDIN>;
chomp($str);
print "the result:/n";
$i=0;
while (<Hand>)
{
$i++;
while (/$str/g)
{
print "line".$i.": ".$_;
}
}
保存为search.pl
C:/>perl search.pl
input file:hello.txt
input the string to search: hello
the result:
line2: this is a hello test.
lien5: helloworld.
这个程序运行特别快.
- 一个在文本文件搜索指定字符串的程序
- 在一个10M的文本文件中搜索指定字符串
- 切割大文本文件并搜索指定的字符串
- java程序,编写一个方法,输出在一个字符串中,指定字符串输出的次数
- [Shell]在一个目录及其子目录内的指定类型的文件中搜索某个字符串
- 在指定文本文件中删除指定字符串C语言
- 文本文件以指定的字符串分割
- 找出包含指定字符串的文本文件名称
- 读取文本文件内指定行数的字符串并赋值给一个变量
- 笔试题---给定一个字符串,在一个文本文件中找出包含该字符串的个数
- python针对指定目录内的文本文件的关键字搜索
- 搜索指定类型的文本文件并转换为unicode
- 如何搜索指定目录下的所有文本文件
- 在一个字符串的相同指定长度间隔处插入指定字符串
- 提取海量文本文件中含有指定字符串的行
- 从文本文件里抽取包含指定字符串的行
- 在一个字符串中搜索某个特定的字符值
- 编写一个方法,输出在一个字符串中,指定字符串出现的次数
- 深入剖析Java编程中的中文问题及建议最优解决方法--下篇
- c#基础——关于类
- 怎么判断SQLServer中SQLServerAgent是否已经启动?
- 有谁调试成功过NiceErp (Delphi) 的源代码呀?求助,重谢!
- Web下HelloWorld
- 一个在文本文件搜索指定字符串的程序
- 用Perl实现单词计数器
- OSI网络结构的七层模型--网络大典
- D3DXMatrixMultiplyTranspose 函数
- 网站配色奥秘大公开
- 17种正则表达式
- ASP实现无组件文件上传的代码
- DirectX
- 左撇子和右撇子,谁是强者?