Gentoo Archives: gentoo-user

From: hamilton <hamilton@×××××.com>
To: gentoo-user@l.g.o
Subject: [gentoo-user] Re: OT: cut replacement with bash builtins
Date: Sun, 27 Feb 2011 20:11:26
Message-Id: 4d8ebcfffb7efb9fb1685df5092a61e4@mail.nethamilton.net
In Reply to: [gentoo-user] OT: cut replacement with bash builtins by Florian Philipp
1 On Sun, 27 Feb 2011 21:01:46 +0100, Florian Philipp wrote:
2 > Hi list!
3 >
4 > I'm currently streamlining some of my shell scripts to avoid
5 > unnecessary
6 > process calls where bash itself is powerful enough.
7
8 My experience (take it for whatever you think it's worth) is that
9 doing so often just makes things harder to follow and maintain.
10 It's very unlikely that the overhead of a fork+exec is appreciably
11 slowing your process down. Having said that (and in that vein) there
12 is something more straightforward which may be useful:
13
14 [...]
15
16 > My current solution is using two string operations:
17 > string='foo:bar:foo'
18 > # remove everything up to and including first ':'
19 > second_and_following=${string#*:}
20 > # remove everything from the first ':' following
21 > second_field=${second_and_following%%:*}
22
23 second_field = $(echo $string | awk -F: '{print $2}')
24
25
26 --
27 Jon Hamilton
28 hamilton@×××××.com

Replies

Subject Author
Re: [gentoo-user] Re: OT: cut replacement with bash builtins Florian Philipp <lists@×××××××××××.net>