diff options
-rwxr-xr-x | bsgrep | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -29,11 +29,11 @@ $SIG{__WARN__} = sub { }; sub grep_usage { - print "usage: $self [--help | --version | -[iklnrsvwq] [-d char] ...] <regex> [<file> ...]\n"; + print "usage: $self [--help | --version | -[iklnrsvwqz] [-d char] ...] <regex> [<file> ...]\n"; } sub grep_options { - getopts('hd:vlkinrwsq', \%opt) || exit 1; + getopts('d:hiklnqrsvwz', \%opt) || exit 1; if($opt{h}) { grep_usage(); exit(0); @@ -43,16 +43,17 @@ sub grep_options { sub print_line { print "$ARGV:" if $filecount > 1; print "$start_line:" if $opt{n}; - print "$_[0]\n"; + print $_[0]; + print $opt{z} ? "\0" : "\n"; } sub join_help { - print "usage: $self [--help | --version | -[knw] [-d char] ...] [<file> ...]\n"; + print "usage: $self [--help | --version | -[knwz] [-d char] ...] [<file> ...]\n"; exit 0; } sub join_options { - getopts('hd:knw', \%opt) || exit 1; + getopts('hd:knwz', \%opt) || exit 1; join_help() if $opt{h}; } @@ -121,6 +122,8 @@ $filecount = @ARGV; # used to decide whether to print filename prefixes. $cont = quotemeta($opt{d} // '\\'); +$/ = "\0" if $opt{z}; + while(<>) { chomp; if(s/\r//) { @@ -170,9 +173,9 @@ bsjoin - join lines with backslash continuation =head1 SYNOPSIS -bsgrep B<[-hknw]> [I<file> I<...>] +bsgrep [B<[-hknwz]> B<-d> I<char> I<...>] [I<file> I<...>] -bsjoin B<[-hvlkinrws]> [I<file> I<...>] +bsjoin [B<[-hiklnqrsvwz]> B<-d> I<char> I<...>] [I<file> I<...>] =head1 DESCRIPTION @@ -227,6 +230,11 @@ the Perl B<\b> syntax in the regex. Prints a short help message and exits. Not compatible with B<grep>, which uses B<-h> for something else. +=item -z + +Use zero bytes (ASCII NUL) rather than newlines for line terminators, +for both input and output. Same as B<grep>. + =item --version Print the version of B<bsgrep> and exit. |