zoukankan      html  css  js  c++  java
  • 在指定文件夹中的文件中查找包含指定字符的行(这个小东西不错[Perl]) zhumao

    #!/usr/bin/perl -w
    printf"write the path you want to search files:";
    $searchdir=<STDIN
    >;
    chomp $searchdir
    ;
    printf "Input search string:"
    ;
    $searchstr=<STDIN
    >;
    chomp $searchstr
    ;
    opendir(DIRHANDLE,$searchdir) || die "Cann't open $searchdir !"
    ;
    while(
    $file=readdir DIRHANDLE
    ) {
            if (-
    d "$searchdir/$file"
    ) {
                    
    printf "$searchdir/$file is a directory!\n"
    ;
            } else {
                    
    open(FileHandle, "$searchdir/$file") || die "cann't open $searchdir/$file !\n"
    ;
                    
    $lines=1
    ;
                    while (
    defined($line=<FileHandle
    >)) {
                            
    $back=index($line,$searchstr
    );
                            if (
    $back != -1
    ) {
                                    print
    "$file:$lines:$line"
    ;
                            }
                    
    $lines=$lines+1
    ;
                    }
            }
            
    close(FileHandle
    );
    }
    closedir(DIRHANDLE
    );
  • 相关阅读:
    django实现github第三方本地登录
    django扩展User模型(model),profile
    WSGI
    Linux查看配置文件中未被注释的有效配置行
    virsh 命令
    qemu-img命令
    python logging
    oslo.messaging
    集成kafka的身份认证(SASL/PLAIN)到kubernets环境中
    Helm基础知识
  • 原文地址:https://www.cnblogs.com/zhumao/p/211119.html
Copyright © 2011-2022 走看看