Discussion:
grep for converting decimal to ascii characters?
Ken G. Brown
2008-03-17 11:36:40 UTC
Permalink
I'm trying to figure out a way of converting a list of decimal representations of ascii characters, to their ascii character so I do not need to do it manually.

(\d+) finds the decimal numbers and \1 in the replace field will put them back in, but how do I get them put back in as ascii characters?

I'd like this:

35
123
86
58

to end up something like this:

35 #
123 {
86 V
58 :

or even better have the multiple lines end up like this on one line but I think I can eventually figure that out if I really want.

#{V:

Thx for any tips.

Ken G. Brown
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <bbedit-talk-***@barebones.com>
Jan Leppink
2008-03-18 12:54:21 UTC
Permalink
Hi Ken,
I think you must realise that ascii encoding is beyond the scope of grep. Especially for codes
above 128 there are a lot of encodings that grep knows nothing about (and shouldn't).

But I think there is a workaround by creating pattern and replacement arrays to get what you
want. You can use Perl to create these arrays, But maybe it is easier to write the whole
replacement in Perl and call that script from BBEdit.

Hope this helps you,
Jan Leppink.
Post by Ken G. Brown
I'm trying to figure out a way of converting a list of decimal representations of ascii
characters, to their
Post by Ken G. Brown
ascii character so I do not need to do it manually.
(\d+) finds the decimal numbers and \1 in the replace field will put them back in, but how do
I get them
Post by Ken G. Brown
put back in as ascii characters?
35
123
86
58
35 #
123 {
86 V
or even better have the multiple lines end up like this on one line but I think I can eventually
figure that
Post by Ken G. Brown
out if I really want.
Thx for any tips.
Ken G. Brown
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <bbedit-talk-***@barebones.com>
Ken G. Brown
2008-03-19 13:36:29 UTC
Permalink
Got a Perl filter that does what I need from Ronald on the BBedit Scripting list.
Don't need the ones over 128 right now.
Thx,
Ken
Date: Mon, 17 Mar 2008 10:48:26 -0400
Subject: Re: regex for converting decimal to ascii?
Content-Type: text/plain; charset=us-ascii
Post by Ken G. Brown
I'm trying to figure out a way of converting a list of decimal representations of ascii characters, to their ascii character so I do not need to do it manually.
(\d+) finds the decimal numbers and \1 in the replace field will put them back in, but how do i get them put back in as ascii characters?
Thx for any tips.
Here's a Perl solution, which you can run as a filter on the selected text.
#!perl -p
s/(\d+)/chr($1)/ge;
Ronald
Hi Ken,
I think you must realise that ascii encoding is beyond the scope of grep. Especially for codes
above 128 there are a lot of encodings that grep knows nothing about (and shouldn't).
But I think there is a workaround by creating pattern and replacement arrays to get what you
want. You can use Perl to create these arrays, But maybe it is easier to write the whole
replacement in Perl and call that script from BBEdit.
Hope this helps you,
Jan Leppink.
I'm trying to figure out a way of converting a list of decimal representations of ascii
characters, to their
ascii character so I do not need to do it manually.
(\d+) finds the decimal numbers and \1 in the replace field will put them back in, but how do
I get them
put back in as ascii characters?
35
123
86
58
35 #
123 {
86 V
or even better have the multiple lines end up like this on one line but I think I can eventually
figure that
out if I really want.
Thx for any tips.
Ken G. Brown
--
<>
--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <***@barebones.com>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to: <bbedit-talk-***@barebones.com>
Loading...