08-30-2009
hi ppl,
I have a basic doubt as to how shell treats strings.
e.g:given a line of data like this "5","6","45","77","89"
extracting the value from each field to a variable will conatin a string("5") or just the number?
If it conatins "5", how do we perform mathematical operations with that variable?
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi
I have a script that loops though lines of a file and reads each line in to a variable ($LINE).
I want to look at the line and split it into it's constituent parts.
e.g. a line might be "This is a string"
I want to then have variables set to each element thus:
A=This
B=is
C=a... (3 Replies)
Discussion started by: gazingdown
3 Replies
2. UNIX for Dummies Questions & Answers
I have gone through all the threads in the forum and tested out different things. I am trying to split a 3GB file into multiple files. Some files are even larger than this.
For example:
split -l 3000000 filename.txt
This is very slow and it splits the file with 3 million records in each... (10 Replies)
Discussion started by: madhunk
10 Replies
3. Shell Programming and Scripting
Hi,
I am new to scripting and need help splitting a string using space as the delimiter.
How can I do that?
I want the result to be stored in an Array.
I tried using
set -A arr $(echo $FILE)
echo $arr
The result of the above was ''.
Thanks. (2 Replies)
Discussion started by: newbie187
2 Replies
4. Shell Programming and Scripting
I need to split the string msu1_2
It should be generic for any string of the form msu<digits>_<digits>
so that i get $X =1 and $Y = 2
Please help
Thanks (5 Replies)
Discussion started by: asth
5 Replies
5. Shell Programming and Scripting
Hi,
if i use this code
awk '/String/{n++}{print > f n}' f=file input
I get "input" splited this way
file1
String
1515
1354
2356
file 2
String
4531
0345
5345 (3 Replies)
Discussion started by: aloctavodia
3 Replies
6. Shell Programming and Scripting
Hi
I am facing a problem in spitting a string.
Here is the string
--------------------
subject1=10;subject2=30;subject3=40;subjectcode=10001;...
Now, I want only marks not the subject code. (there can be 'n' subjects)
ie.
10
30
40
My doubt
----------
How do I... (5 Replies)
Discussion started by: jionnet
5 Replies
7. Shell Programming and Scripting
Hello;
I have a file consists of 4 columns separated by tab. The problem is the third fields. Some of the them are very long but can be split by the vertical bar "|". Also some of them do not contain the string "UniProt", but I could ignore it at this moment, and sort the file afterwards. Here is... (5 Replies)
Discussion started by: yifangt
5 Replies
8. Shell Programming and Scripting
here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb
cat dump.sql
INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies
9. Shell Programming and Scripting
Hi Experts.
I'm stuck with the below AWK code where i'm trying to move the records containing any special characters in the last field to a bad file.
awk -F, '{if ($NF ~ /^|^/) print >"goodfile";else print >"badfile"}' filename
sample data
1,abc,def,1234,A *
2,bed,dec,342,* A ... (6 Replies)
Discussion started by: shell_boy23
6 Replies
10. Shell Programming and Scripting
Hey guys, I've been trying to find an answer to this, and I've been reading up on awk as much as possible, but I'm at a loss at the moment.
I'll start off by saying I'm trying to learn, so forgive me if I ask questions about your answers.
Here is what I'm trying to accomplish. I have a long... (8 Replies)
Discussion started by: ShadowBlade72
8 Replies
LEARN ABOUT OPENDARWIN
lindex
lindex(n) Tcl Built-In Commands lindex(n)
__________________________________________________________________________________________________________________________________________________
NAME
lindex - Retrieve an element from a list
SYNOPSIS
lindex list ?index...?
_________________________________________________________________
DESCRIPTION
The lindex command accepts a parameter, list, which it treats as a Tcl list. It also accepts zero or more indices into the list. The |
indices may be presented either consecutively on the command line, or grouped in a Tcl list and presented as a single argument. |
If no indices are presented, the command takes the form: |
lindex list |
or |
lindex list {} |
In this case, the return value of lindex is simply the value of the list parameter. |
When presented with a single index, the lindex command treats list as a Tcl list and returns the index'th element from it (0 refers to the
first element of the list). In extracting the element, lindex observes the same rules concerning braces and quotes and backslashes as the
Tcl command interpreter; however, variable substitution and command substitution do not occur. If index is negative or greater than or
equal to the number of elements in value, then an empty string is returned. If index has the value end, it refers to the last element in
the list, and end-integer refers to the last element in the list minus the specified integer offset.
If additional index arguments are supplied, then each argument is used in turn to select an element from the previous indexing operation, |
allowing the script to select elements from sublists. The command, |
lindex $a 1 2 3 |
or |
lindex $a {1 2 3} |
is synonymous with |
lindex [lindex [lindex $a 1] 2] 3 |
EXAMPLES
|
lindex {a b c} => a b c |
lindex {a b c} {} => a b c |
lindex {a b c} 0 => a |
lindex {a b c} 2 => c |
lindex {a b c} end => c |
lindex {a b c} end-1 => b |
lindex {{a b c} {d e f} {g h i}} 2 1 => h |
lindex {{a b c} {d e f} {g h i}} {2 1} => h |
lindex {{{a b} {c d}} {{e f} {g h}}} 1 1 0 => g |
lindex {{{a b} {c d}} {{e f} {g h}}} {1 1 0} => g |
SEE ALSO
list(n), lappend(n), linsert(n), llength(n), lsearch(n), lset(n), lsort(n), lrange(n), lreplace(n) |
KEYWORDS
element, index, list
Tcl 8.4 lindex(n)