Need Grep help to get first digit (or letter) in each row

168 views
Skip to first unread message

Howard

unread,
Jan 16, 2022, 6:16:04 PM1/16/22
to BBEdit Talk
Using the input data below and using Grep, I need either the first digit  or letter extracted from each row (just one per row), so the output looks like what is shown below. Though the output is displayed here in horizontal format, I need the actual output in vertical format without any commas.
Howard

Output
9, 3, D, 6, 8, 5, 3, 9, 5, 2, 7, 4, 3, D, 8, 7

Input data:
*9/HD
*3D/5
*D1/H97
*69/8HD
*87/HD
57983/H
*3
*97D/8H
*5D/H
*2/D3H
*7H/8
*4/H
*3/D5
*D7/9
*84/H
7DH/9

Tom Robinson

unread,
Jan 16, 2022, 8:12:29 PM1/16/22
to BBEdit Talk
^[^a-z0-9]*(.).*$

at beginning of line
[^a-z0-9] look for anything which isn’t a-z 0-9
0 or more times
(.) any single character (i.e. a-z 0-9), and ‘capture’ it for replacement pattern
★ any characters
$ end of line

Replace with

\1

Cheers


--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://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 bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/5bc28303-df27-47a4-a6ca-a0e0d20e6a43n%40googlegroups.com.

Christopher Waterman

unread,
Jan 16, 2022, 8:38:24 PM1/16/22
to bbe...@googlegroups.com
Hello Howard,

Find: ^[^0-9A-Z]?([0-9A-Z]).*

Replace: \1



— Chris(topher)?

Howard

unread,
Jan 17, 2022, 9:02:29 PM1/17/22
to BBEdit Talk
Thanks Tom and Christopher.
Howard

Reply all
Reply to author
Forward
0 new messages