hanslub42 / rlwrap

A readline wrapper
GNU General Public License v2.0
2.59k stars 151 forks source link

[QUESTION] Make sure command output has a newline at the end #183

Open lobre opened 1 year ago

lobre commented 1 year ago

I am trying to use rlwrap with sam -d for structural regular expressions in the taste of ed. However, sam sometimes outputs text that does not contain new lines. Here is an example.

$ cat input.txt
&Book: Programming Perl
&Author: Larry Wall&Author: Tom Christiansen&Author: Jon Orwant
&ISBN: 0-596-00027-8

And now I do this (note that sam is part of plan9port so should be invoked as 9 sam).

$ rlwrap 9 sam -d input.txt
 -. input.txt
2x/^&[^&]+
&Author: Larry Wall▌

Here, 2x/^&[^&]+ means "taking line 2 as input, extract text that starts at the beginning of the line with & and that ends before another &".

You can see that sam did not output a newline character ( represents the cursor position), because it extracted only the inline part, which is normal.

But I would still like rlwrap to always display a newline at the end of outputs.

I tried with a filter with this, but I still don't have a newline at the end.

rlwrap -z "makefilter awk '{print}'" 9 sam -d -a input.txt

Do you have guidance on how to do this? Thanks.