Windows – 如何使批处理文件像使用Perl的简单grep一样行事?
发布时间:2020-12-14 01:46:18 所属栏目:Windows 来源:网络整理
导读:我已经知道这个问题的明显答案:“只需下载插入最喜欢的窗口grep或类似grep的工具”.但是,我在当地IT人员严格控制的环境中工作,我们允许在我们的电脑上.只需说:我可以在 Windows XP上访问Perl.这里有一个快速的Perl脚本,我想出了这个我想要的,但是我没有想
我已经知道这个问题的明显答案:“只需下载<插入最喜欢的窗口grep或类似grep的工具>”.但是,我在当地IT人员严格控制的环境中工作,我们允许在我们的电脑上.只需说:我可以在
Windows XP上访问Perl.这里有一个快速的Perl脚本,我想出了这个我想要的,但是我没有想到如何设置一个批处理文件,以便我可以管道命令输出到它,或传递一个文件(或文件列表?)作为“grep”表达式后的一个参数:
perl -n -e "print $_ if (m![expression]!);" [filename] 如何编写一个批处理脚本,我可以做一些例如: dir | grep.bat mypattern grep.bat mypattern myfile.txt 编辑:即使我标注了另一个“答案”,我想给Ray Hayes answer作贡献,因为它真的是“Windows的方式”,即使另一个答案在技术上更接近我想要的.
我写了一段时间:
@rem = '--*-Perl-*-- @echo off perl -x -S %0 %* goto endofperl @rem -- BEGIN PERL -- '; #!d:/Perl/bin/perl.exe -w #line 10 use strict; #use Test::Setup; use Getopt::Long; Getopt::Long::Configure ("bundling"); my $ignore_case = 0; my $number_line = 0; my $invert_results = 0; my $verbose = 0; my $result = GetOptions( 'i|ignore_case' => $ignore_case,'n|number' => $number_line,'v|invert' => $invert_results,'verbose' => $verbose,); my $regex = shift; if ( $ignore_case ) { $regex = "(?i:$regex)"; } $regex = qr/$regex/; print "$regex=$regexn"; if ( $verbose ) { print "Verbose: Ignoring case.n" if $ignore_case; print "Verbose: Printing file name and line number.n" if $number_line; print "Verbose: Inverting result set.n" if $invert_results; print "n"; } @ARGV = map { glob "$_" } @ARGV; while ( <> ) { my $matches = m/$regex/; next unless $matches ^ $invert_results; print "$ARGV:$.:" if $number_line; print; } __END__ :endofperl (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 如何在Windows 7中使用cmd使用cURL发布XML数据?
- 在Windows下编译适用于PHP 5.2.12及5.2.13的eAccelerator.d
- windows-services – 监控单个窗口服务的性能
- windows – 无法添加对’Newtonsoft.Json’的引用
- Qt QDialog将窗体变为顶层窗体(activateWindow(); 和 rais
- windows – AD:你能成为无限团体的成员吗?
- .net – Task <>和IAsyncOperation <>
- windows – R markdown v2 to pdf.当绘图中的非拉丁字符时转
- Windows上的低级是什么:C库或相应的Win32 API函数?
- Windows – Visual Studio代码安装位置
推荐文章
站长推荐
热点阅读