A program that searches for specified strings in text files

xiaoxiao2021-03-06  73

Implemented with Perl.

Print "INPUT FILE:";

$ FILE = ;

CHOMP ($ file);

Open (Hand, $ file) || DIE "can not open file";

Print "Input the String to Search:";

$ Str = ;

CHOMP ($ STR);

Print "The result: / n";

$ I = 0;

While ()

{

$ i ;

While (/ $ STR / G)

{

Print "line". $ I. ":". $ _;

}

}

Save as 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.

This program is run very fast.

转载请注明原文地址:https://www.9cbs.com/read-109093.html

New Post(0)