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: Jose E. Marchesi
Subject: Re: [bug-recutils] Unable to assign the value of Count contained in a variable to -n option
Date: Tue, 10 Jul 2018 13:40:34 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

    >         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!

Yes, also -c knows about -n, -t, -e and the other selection options...



reply via email to

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