On 03/26/2019, at 05:36, Vlad Ghitulescu <[email protected]
<mailto:[email protected]>> wrote:
> I have a bunch (64 exactly :-) lines selected (copied from an iTunes playlist
> and inserted in BBEdit), like this 5 ones
>
> Another One Bites The Dust 3:37
> Bicycle Race 3:04
> Bohemian Rhapsody 5:58
> Breakthru 4:09
> Bring Back That Leroy Brown 2:15
>
> and I would like to prepend a number (beginning with 1) in this format
>
> 1 Another One Bites The Dust 3:37
> 2 Bicycle Race 3:04
> 3 Bohemian Rhapsody 5:58
> 4 Breakthru 4:09
> 5 Bring Back That Leroy Brown 2:15
Hey Vlad,
BBEdit's Add/Remove Line Numbers tool is easy to use, but is very limited in
that it can't deal with number termination characters and such.
Personally I think Bare Bones needs to add a suffix character string to the
tool, so it can more versatilely handle typical line numbering use-cases.
Probably the simplest way to handle this task is with a little awk in a BBEdit
Text Filter. Bind it to a keyboard shortcut and go-to-town.
#!/usr/bin/env bash
awk '{print NR ". " $0}'
** The 'NR' token in awk means Number of Records processed – and '$0' is the
whole record (or line) being processed.
The `nl` command line tool is specifically designed for numbering lines, and
has a few tricks up it's sleeve:
#!/usr/bin/env bash
nl -n ln -w 2 -s ' ' | sed -E 's!^([0-9]+)!\1.!'
** Unfortunately (and strangely) it does NOT have a built-in number-suffix
character-string.
In sed I typically replace the canonical '/' command-separator-character with
an exclamation point, because this reads better for me – and I can avoid the
leaning-toothpick effect when finding/replacing forward slashes.
On 03/26/2019, at 08:08, ThePorgie <[email protected]
<mailto:[email protected]>> wrote:
> There was a post in this group to do this very thing. I can no longer find it
> to credit the creator. However what he posted was to put this code into a
> BBedit file:
That was posted by me back in December of 2018.
For Vlad's job it can be simplified to this:
#!/usr/bin/env perl -sw
use utf8;
my $cntr = 0;
while (<>) {
print ++$cntr.". $_";
}
--
Take Care,
Chris
--
This is the BBEdit Talk public discussion group. If you have a
feature request or need technical support, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <https://www.twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/bbedit.