aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2025-02-02 16:47:20 -0500
committerB. Watson <urchlay@slackware.uk>2025-02-02 16:47:20 -0500
commitfd9d3fae5c74f9f06ccfcc139ca37954b3abc117 (patch)
tree6f90c452943b287e4853520414251c13e8eddfcd
parent29c35ba17c7a73fe495dc87d2d16e6fef2231065 (diff)
downloadmisc-scripts-fd9d3fae5c74f9f06ccfcc139ca37954b3abc117.tar.gz
bsgrep: cosmetics, docs.
-rwxr-xr-xbsgrep17
1 files changed, 10 insertions, 7 deletions
diff --git a/bsgrep b/bsgrep
index 65d138c..bae517d 100755
--- a/bsgrep
+++ b/bsgrep
@@ -130,15 +130,13 @@ while(<>) {
}
}
if(/$cont\s+$/) {
- warn "$self: $ARGV, line $.: whitespace after continuation, malformed input?\n" unless $opt{s};
+ warn "$self: $ARGV:$.: whitespace after continuation, malformed input?\n" unless $opt{s};
}
s/^\s+// if $out && $opt{w};
$start_line = $. unless defined $out;
$out .= $_;
if(/$cont$/) {
- if($opt{k}) {
- $out .= "\n";
- } else {
+ if(!$opt{k}) {
$out =~ s/$cont$//;
}
} else {
@@ -149,7 +147,7 @@ while(<>) {
# reset $. on each new file (perldoc -f eof)
if(eof) {
if($out) {
- warn "$self: $ARGV: last line ends with continuation\n" unless $opt{s};
+ warn "$self: $ARGV:$.: last line ends with continuation\n" unless $opt{s};
handle_line($out);
undef $out;
}
@@ -189,6 +187,9 @@ options, and it uses Perl regular expressions rather than POSIX.
Input is read from one or more files, or standard input if no files
are given. Output goes to standard output.
+The search is done after lines are joined together, so the regex can
+match text split across continuation lines.
+
If B<bsgrep> is run as B<bsjoin> (via symbolic or hard link, or just
copying the executable), it will simply join together continued lines
without searching for anything. In this mode, only the B<-k>, B<-n>,
@@ -206,12 +207,14 @@ Use I<char> as the continuation character, rather than a backslash.
=item -k
-Keep the backslashes and newlines when joining continued lines together.
+Keep the continuation characters when joining continued lines together.
This option does not exist in B<grep>.
=item -n
-Prefix output lines with line numbers (same as B<grep>).
+Prefix output lines with line numbers (same as B<grep>). For lines
+that are split with continuation characters, the line number will be
+that of the first line in the set.
=item -w