help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] first part


From: Eric Blake
Subject: Re: [Help-bash] first part
Date: Sat, 21 May 2016 06:49:58 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

[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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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