bug-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] first part


From: Val Krem
Subject: Re: [Help-bash] first part
Date: Sat, 21 May 2016 22:44:52 +0000 (UTC)

Hi All,

I am sorry, wrong place to ask.






On Saturday, May 21, 2016 7:50 AM, Eric Blake <address@hidden> wrote:
[not a bug report, so I'm dropping bug-bash]


On 05/21/2016 06:44 AM, Val Krem wrote:
> 
> 
> Hi all,
> I  have field  that look like the following
> 124-20-25
> 014-2012-26
> 1024-212-27
> 1-001-29
> 
> I want extract the first part of the string,  prior to the first "-"
> 124
> 014
> 1024
> 
> 1
> 
> How do I do I that?

Are you sure this is not a homework question? You haven't even told us
what you tried. Don't expect us to do all your work for you.

Unless your actual problem is more complex, bash's ${var%%pattern} does
what you want:

$ for line in 124-20-25 014-2012-26 1024-212-27 1-001-29
> do echo ${line%%-*}; done

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


reply via email to

[Prev in Thread] Current Thread [Next in Thread]