07-15-2006
Simplifying the For loop
Is there a way to simplify stating 1 through to 10, for example in a for loop construct?
for x in 1 2 3 4 5 6 7 8 9 10
do
....
done
I have tried [1-10] (1-10) with no luck.. thanks
7 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I need to do a substitution: CPF to ,C,P,F, CPM to ,C,P,M, SPF to ,S,P,F etc. I can do each of them with separate substitutions e.g. s/CPF/,C,P,F/ but I'd like to know if there is a more elegant solution. In general, how can I use the results of the search in the substitution, ... (3 Replies)
Discussion started by: wvdeijk
3 Replies
2. Shell Programming and Scripting
tcpdump -nr testdump|awk '!/:/;gsub(/^+|+$/,""){print $3};a!~$0;{a=$0};{print $3};!/length/;/./;!/11\:/;!/8 7 6 5 4 3 2 1/;!/UDP/{b=$0} END {for (j=i-1; j>=0; ) print b };{for (i=NF; i>0; i--) printf("%s ",i);printf ("\n")}'
*NOTE IN j>=0 the ; ) was given a space since a smiley is showing up...... (1 Reply)
Discussion started by: sil
1 Replies
3. UNIX for Advanced & Expert Users
Hi,
Is there a way to simplify the below script? Because I am having problems executing this if I added this to CRON. Also, you may notice that its objective is to put all information in one file (rm1.txt). And in addition file "sRMR_6.txt" to sRMR_23.txt" changes its information everyday.... (4 Replies)
Discussion started by: vibora
4 Replies
4. Shell Programming and Scripting
hi friends,
im new to scripting and am tiring out to valid an ip address if user inputs
9 : 003 : 0 : 0 : 100 : 256 ,i need to suppress all leading zeros and single zero
ie out put for the same should be
9 : 3 : : : 100 : 256 can any help using awk ,regular expression to split the string... (1 Reply)
Discussion started by: sandeepjeede
1 Replies
5. Shell Programming and Scripting
the code below is a small fragment of the actual line, in fact i have about 20 values i'm comparing and want to know if it can be simplified. other than the x.xx.xx format of the value they have nothing in common
if || || ; then
do this
else
do this
fiany suggestions? (6 Replies)
Discussion started by: crimso
6 Replies
6. Shell Programming and Scripting
Hi all, I don't have much experience with shell scripting and I was wondering if there's a shorter way to write this.
Basically, given a list of strings separated by new lines, I want to prepend each string with a prefix and separate the strings with commas
i.e.
stra
strb
strc
becomes... (3 Replies)
Discussion started by: vshan
3 Replies
7. UNIX for Beginners Questions & Answers
I have a file like this:
FileName,Well,Sample Description,Size ,Calibrated Conc. ,Assigned Conc. ,Peak Molarity ,Area,% Integrated Area,Peak Comment,Observations
2017-11-15 - 13.49.50.D1000,EL1,Electronic Ladder,25,5.22,,321,0.803,,,Lower Marker
2017-11-15 - 13.49.50.D1000,EL1,Electronic... (6 Replies)
Discussion started by: Xterra
6 Replies
LEARN ABOUT REDHAT
foreach
foreach(n) Tcl Built-In Commands foreach(n)
__________________________________________________________________________________________________________________________________________________
NAME
foreach - Iterate over all elements in one or more lists
SYNOPSIS
foreach varname list body
foreach varlist1 list1 ?varlist2 list2 ...? body
_________________________________________________________________
DESCRIPTION
The foreach command implements a loop where the loop variable(s) take on values from one or more lists. In the simplest case there is one
loop variable, varname, and one list, list, that is a list of values to assign to varname. The body argument is a Tcl script. For each
element of list (in order from first to last), foreach assigns the contents of the element to varname as if the lindex command had been
used to extract the element, then calls the Tcl interpreter to execute body.
In the general case there can be more than one value list (e.g., list1 and list2), and each value list can be associated with a list of
loop variables (e.g., varlist1 and varlist2). During each iteration of the loop the variables of each varlist are assigned consecutive
values from the corresponding list. Values in each list are used in order from first to last, and each value is used exactly once. The
total number of loop iterations is large enough to use up all the values from all the value lists. If a value list does not contain enough
elements for each of its loop variables in each iteration, empty values are used for the missing elements.
The break and continue statements may be invoked inside body, with the same effect as in the for command. Foreach returns an empty string.
EXAMPLES
The following loop uses i and j as loop variables to iterate over pairs of elements of a single list. set x {} foreach {i j} {a b c d e f}
{
lappend x $j $i } # The value of x is "b a d c f e" # There are 3 iterations of the loop.
The next loop uses i and j to iterate over two lists in parallel. set x {} foreach i {a b c} j {d e f g} {
lappend x $i $j } # The value of x is "a d b e c f {} g" # There are 4 iterations of the loop.
The two forms are combined in the following example. set x {} foreach i {a b c} {j k} {d e f g} {
lappend x $i $j $k } # The value of x is "a d e b f g c {} {}" # There are 3 iterations of the loop.
SEE ALSO
for(n), while(n), break(n), continue(n)
KEYWORDS
foreach, iteration, list, looping
Tcl foreach(n)