Trimming lines with a filter

34 views
Skip to first unread message

Christopher Finazzo

unread,
Apr 10, 2024, 10:49:41 AMApr 10
to BBEdit Talk
A number of my projects standardize on 80 characters per line. I have tried to use Process Lines to simplify this process:

1) Text > Process Lines Containing...
2) Check the Grep checkbox
3) Use the following pattern to target all lines with 80 or more characters:

.{{0,79}}

I've done it enough times that it would be useful to have this run as a filter so that I don't need to invoke it manually each time. However, a (admittedly shitty) first pass with ChatGPT to wrap these steps in a script returns a different result.

An example script is shown below.

    #!/bin/bash

    # Read input line by line
    while IFS= read -r line; do
    # Delete characters longer than 80 characters
    modified_line=$(echo "$line" | sed -E 's/.{81,}//g')
      echo "$modified_line"
    done

Is GPT just dumb or am I missing something obvious?

Rich Siegel

unread,
Apr 10, 2024, 10:58:31 AMApr 10
to BBEdit Talk
On 10 Apr 2024, at 10:49, Christopher Finazzo wrote:

> A number of my projects standardize on 80 characters per line. I have tried
> to use Process Lines to simplify this process:
>
> 1) Text > Process Lines Containing...
> 2) Check the Grep checkbox
> 3) Use the following pattern to target all lines with 80 or more characters:
>
> .{{0,79}}
>
> I've done it enough times that it would be useful to have this run as a
> filter so that I don't need to invoke it manually each time.

You could create a text factory with a single "Process Lines Containing" step, and then put that in BBEdit's "Text Filters" support folder; seems like that would do the job. (You can shorten the path by using "Apply Text Transform" to test the operation, then employ the "Save as Text Factory" button.)

Enjoy,

R.

--
Rich Siegel Bare Bones Software, Inc.
<sie...@barebones.com> <https://www.barebones.com/>

Someday I'll look back on all this and laugh... until they sedate me.
Reply all
Reply to author
Forward
0 new messages