From 34d1fb0b762d733216bb35868904cc72eddf3d6a Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Sun, 2 Feb 2025 17:02:24 -0500 Subject: bsgrep: add -z option. --- bsgrep | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'bsgrep') diff --git a/bsgrep b/bsgrep index bae517d..ed57824 100755 --- a/bsgrep +++ b/bsgrep @@ -29,11 +29,11 @@ $SIG{__WARN__} = sub { }; sub grep_usage { - print "usage: $self [--help | --version | -[iklnrsvwq] [-d char] ...] [ ...]\n"; + print "usage: $self [--help | --version | -[iklnrsvwqz] [-d char] ...] [ ...]\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] ...] [ ...]\n"; + print "usage: $self [--help | --version | -[knwz] [-d char] ...] [ ...]\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 I<...>] +bsgrep [B<[-hknwz]> B<-d> I I<...>] [I I<...>] -bsjoin B<[-hvlkinrws]> [I I<...>] +bsjoin [B<[-hiklnqrsvwz]> B<-d> I I<...>] [I 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, 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. + =item --version Print the version of B and exit. -- cgit v1.2.3