tcl-getting the index of a certain value of a list


 
Thread Tools Search this Thread
Top Forums Programming tcl-getting the index of a certain value of a list
# 1  
Old 02-23-2011
Question tcl-getting the index of a certain value of a list

i was trying to get the index of a certain value in a list...

set foo[list 1 2 3 4 5]

so if I wanted the index of the value of 4? I tried googling but didn't have much luck..anyone done this before?

I tried using this guy:
string index string charIndex

and a few others..
# 2  
Old 02-24-2011
You are looking for something like the lsearch command:

% set foo[list 1 2 3 4 5]
1 2 3 4
% lsearch $foo 4
3

# the -integer option is reasonable here, since we are searching into a list of integers:
% lsearch -integer $foo 4
3


Tcl Built-In Commands - lsearch manual page
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

TCL script to extract the file name and then create two independent list

I am having one problem as stated below Problem Description I am having some "sv" extension files , I am using "glob" to extract the matching files , Now in these matching files , I need to split them and extract the elements and create different lists. For example set files This... (1 Reply)
Discussion started by: kshitij
1 Replies

2. Shell Programming and Scripting

Need Help in Index

I am having data in XML format and trying to extract codes form two fields called <String>, below is the data. <Node>tollfree<Condition>BooleanOperator<Operation>AND</Operation><Condition>BooleanOperator<Operation>NOT</Operation><Condition>FieldSelection<Field Context="ALL fields"... (7 Replies)
Discussion started by: rramkrishnas
7 Replies

3. UNIX and Linux Applications

Index server

Hi guys, I have postgresql server with huge amount of data, nearly 2 billion records. each record is at most 50 bytes(4 integer fields). I need to build index on all column to do fast reporting. but indexes becomes bloat after some time. almost 80% of database size is because of its huge... (0 Replies)
Discussion started by: majid.merkava
0 Replies

4. Shell Programming and Scripting

Get index value by awk

HI All, I would like to pass a integer and get all values under this index the by using awk. Could anyone help? Thanks :> input: 1,2,3,4,5,6,7 1,2,3,48,5,6,7 1,2,3,4,5,6,7 e.g. i pass 4 to awk command output: 4 48 4 Video tutorial on how to use code tags in The UNIX and Linux... (8 Replies)
Discussion started by: mimilaw
8 Replies

5. UNIX for Dummies Questions & Answers

I'm unable to run Keyed List commands(in ubuntu's terminal and Evolane Tcl Engine)

I'm trying to run these commands (keylset,keylget) but i keep getting a error message "invalid command name "keylset"". I've tried running it on both ubuntu's terminal and also Evolane Tcl Engine. Any idea what could be the problem? (1 Reply)
Discussion started by: abe171
1 Replies

6. UNIX for Dummies Questions & Answers

string index

I have a line "My name is Deepak" How can i search a string Deepak in the line and find out its index position. Here in this case the result should be 12. (3 Replies)
Discussion started by: dr46014
3 Replies

7. Shell Programming and Scripting

Sort from start index and end index in line

Hi All, I have a file (FileNames.txt) which contains the following data in it. $ cat FileNames.txt MYFILE17XXX208Sep191307.csv MYFILE19XXX208Sep192124.csv MYFILE20XXX208Sep192418.csv MYFILE22XXX208Sep193234.csv MYFILE21XXX208Sep193018.csv MYFILE24XXX208Sep194053.csv... (5 Replies)
Discussion started by: krish_indus
5 Replies

8. UNIX for Dummies Questions & Answers

wh inode index starts from 1 unlike array index (0)

brothers why inode index starts from 1 unlike array inex which starts from 0 its a question from the design of unix operating system of maurice j.bach i need to know the answer urgently...someone help please (1 Reply)
Discussion started by: sairamdevotee
1 Replies

9. Filesystems, Disks and Memory

why the inode index of file system starts from 1 unlike array index(0)

why do inode indices starts from 1 unlike array indexes which starts from 0 its a question from "the design of unix operating system" of maurice j bach id be glad if i get to know the answer quickly :) (0 Replies)
Discussion started by: sairamdevotee
0 Replies

10. Shell Programming and Scripting

What is index?

hi, :) In a shell script i came accross the following lines 1.for i in ` find /home/oracle -name ch' 2.do 3.echo $i 4.idx=`expr index $i .` 5.done Here iam not able to understand the porpose of the word "index" in line 4. any help ? cheers RRK (3 Replies)
Discussion started by: ravi raj kumar
3 Replies
Login or Register to Ask a Question