Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: convert number
- X-seq: zsh-users 15068
- From: Christian Walther <cptsalek@xxxxxxxxx>
- To: tartifola@xxxxxxxxx
- Subject: Re: convert number
- Date: Wed, 19 May 2010 20:39:48 +0200
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=+rARzdsO8iuYEaO3Hqp2d0xhPgx2c0m/pI4fsoo2mo8=; b=l3k12qXrnm8mMhuD1eWyU8TjOjII67d9w5H9Bz5+vdd6Tc8YdEYUjIPUIj3A0u4Djb QFbrS8bOMyuni1i2kNscWZZ5HP/K7j5x5YWZvZtZPD+s8XvjrgGj2pd4gf636mJny8bx IyNOoNslKtxb4jSwCvaB27YftYqjzsK9uehAc=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=howvuzi7mm7W9aVPLJm5BV3YLBKfc64sB7zpZvTI80EAepZCWqkE/ilU91ur5BYvBk 8KG8EhLZDYVLyKDwNjREBe2QB0UEEvLqjkEaGOk5lN3+kOHH80V1mn0LRANSm03zt9rk IFyYtv3juDbSuJOCexo41/ElC0N6ImRGIU+Jw=
- In-reply-to: <20100519191103.b712607f.tartifola@xxxxxxxxx>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20100519191103.b712607f.tartifola@xxxxxxxxx>
Hi,
On 19 May 2010 19:11, <tartifola@xxxxxxxxx> wrote:
>
> Hi,
> I'm lost in a shell issue with no clue where to look for a solution.
> I have a very long column of three digit numbers and I need to transform
> each of them into a one digit number according to the following
> "conversion table"
>
> 151 2
> 152 2
> 153 2
> 158 4
> 159 3
> 160 2
> 171 4
> 172 1
> 173 4
if there is no mathematical formula for the "conversion table"
available, I would put this table in a hash, e.g. something like:
typeset -A convtable
convtable[151]=2
convtable[152]=2
etc...
If there is a value that appears very often, such as 2 in your
example, and it's not possible to parse an invalid number (such as
154-157 which doesn't appear to exist in your example), you could drop
every number that needs to be transformed to 2 and use something like:
typeset -A convtable
convtable[158]=4
convtable[159]=3
convtable[171]=4
convtable[172]=1
convtable[173]=4
The transformation would be done as
${convtable[$number]=2}
e.g.
number=158
echo ${convtable[$number]=2}
4
number=151
echo ${convtable[$number]=2}
2
HTH
Christian Walther
Messages sorted by:
Reverse Date,
Date,
Thread,
Author