Re: tr equivalent to sed command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 2012-02-25 at 17:29 +0900, 夜神 岩男 wrote:
> On 02/25/2012 12:43 PM, Patrick O'Callaghan wrote:
> > On Fri, 2012-02-24 at 21:22 +0900, 夜神 岩男 wrote:
> >> I'm trying to move a script from invoking lots of sed and awk to bash
> >> builtins and I'm stumped on something I'm sure is simple.
> >>
> >> Is there a tr equivalent to the following?
> > [...]
> >
> > You realize that tr is not a Bash builtin, right?
> 
> No, I didn't check, actually, thanks for pointing that out. The tr 
> command is probably easier for some of the younger folks who will have 
> to read this later on[1]. Now I'm curious and might run some tests on 
> the two versions and see which is quicker -- though that's totally not 
> the point with scripting (well, isn't supposed to be, anyway).
> 
> -IY
> 
> 1. Rantesque continuation:
> ...as they seem so allergic to learning one or two sed commands that 
> they will instead implement a parse/convert library from scratch in 
> their favorite vanity language complete with intermediate working files 
> and locks... and viola, new dependencies, attack vectors, opportunities 
> for frozen jobs, etc are born.

Quite. It's a matter of developing a nose for the right combination of
tools. In Unix/Linux there's rarely one right answer, but there are many
many wrong ones. Good programmers learn good taste :-)

Somewhat OT:

The other day I came on a nice little problem which at first glance one
would think could be solved directly in Bash:

Given a string constructed as: <prefix><marker><remainder>

Where <marker> is a string matching a (fixed) regular expression and
<prefix> is arbitrary but does not match the RE, return only the
<prefix>.

I convinced myself that the "=~" operator in Bash could handle this, but
it made my head spin. I wound up writing 3 lines of Python (no doubt the
Perlistas out there could do it in one). It not only worked but it's
obviously correct, a property not to be sneezed at.

poc

-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org


[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux