bug-recutils
[Top][All Lists]
Advanced

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

Re: [bug-recutils] Unable to assign the value of Count contained in a va


From: Héctor A . Abreu
Subject: Re: [bug-recutils] Unable to assign the value of Count contained in a variable to -n option
Date: Tue, 10 Jul 2018 07:18:34 -0400
User-agent: Mutt/1.5.23 (2014-03-12)

On Mon, Jul 09, 2018 at 04:15:31PM +0200, Jose E. Marchesi wrote:
> 
>         
>         I have the contacts.rec file below:
>         
>         Name: Granny
>         Phone: +12 23456677
>         
>         Name: Doctor
>         Phone: +12 58999222
>         
>         Name: Dad
>         Phone: +12 88229900
>         
>         And I want to display the Name in the last record using the script
>         script_variable_index.sh below:
>         
>         number_of_records=$(recsel -P "Count(Name)" contacts.rec)
>         name_in_last_record=$(recsel -P Name -n "$number_of_records" 
> contacts.rec)
>         echo "Name in last record: $name_in_last_record"
>         
>         But I get the following output:
>         
>         Name in last record:
>         
>         So, not displaying any Name.
>     
>     That's because the aggregate Count(Name) is returning 3 (there are 3
>     instances of the field Name), whereas -n expects a 0-based index.
> 

Oh my God, you're right. I just needed to subtract -1. Thanks.

> BTW for counting records you can use recsel -c.

Thank you for this -c option, it makes more sense to count records rather than 
counting occurrences of a field, like I was doing!
-- 
Héctor A. Abreu



reply via email to

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