Mailinglist Archive: opensuse (1483 mails)

< Previous Next >
Re: [opensuse] grep sed and awk question
  • From: Marko Koski-Vähälä <marko@xxxxxxxxxxxxxxx>
  • Date: Mon, 13 Feb 2012 01:23:42 +0100
  • Message-id: <20120213002342.GD7882@makkan.koski-vahala>
* lynn <lynn@xxxxxxxxxxxx> [120213 00:40]:
On 02/13/2012 12:05 AM, lynn wrote:
I'm regex'd out of it at the moment.
Given a string like this:

lynn:*:3000002some other stuff100hellolynn:

Is there a way to get the 3000002 into a variable v1 and the 100
into a variable v2? bash? Any recommended starting point?
Thanks,
L x

Thinking out loud:
v1="lynn:*:3000002some other stuff100hellolynn:";echo "${v1//[!0-9]}"
gives:
3000002100

But I may have:
lynn2:*:3000002some other stuff100hellolynn:
which gives:
23000002100

How to select only the 3000002
Thanks
--

Does it have to be grep, sed and awk?



cut -c 9-15



awk -F\: '{print $3}' |cut -c 1-7
< Previous Next >
References