[Purdue-pm] This has to be a thing in sed or something that I just didn't know, right?
Dave Jacoby
jacoby.david at gmail.com
Fri Aug 31 13:56:47 PDT 2018
I know grep gives you the lines and line numbers
grep jacoby -sil *
But what if you wanted to match them and just them? Like, for example, you
wanted to pull all the perl scripts out of your crontab?
crontab -l | match -r '([\w\.\/]*.pl)'
Which you can then sort or sort -u to just see those files.
#!/usr/bin/env perl
use strict ;
use warnings ;
use utf8 ;
use feature qw{ postderef say signatures state } ;
no warnings qw{ experimental::postderef experimental::signatures } ;
use Getopt::Long ;
my $regex ;
GetOptions(
'regex=s' => \$regex
);
exit unless defined $regex;
my @output;
while (<STDIN>) {
push @output , $_ =~ m{$regex}gmix;
}
say join "\n", @output;
If there's a regular thing and I just never learned the right Unix-fu, I'd
love to know.
--
Dave Jacoby
jacoby.david at gmail.com
Don't panic when the crisis is happening, or you won't enjoy it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/purdue-pm/attachments/20180831/17511c1b/attachment-0001.html>
More information about the Purdue-pm
mailing list