Sponsored Content
Full Discussion: Combining lists
Top Forums Shell Programming and Scripting Combining lists Post 303043048 by nezabudka on Thursday 16th of January 2020 08:13:16 AM
Old 01-16-2020
Yes, it's cool.
"${L2[i%lenL2]]}"
This algorithm can be organized even on "awk" or "bc" with a large size of values
Thanks @Scrutinizer
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question on lists

I'm fairly new to shell scripting and would like to know if what I am seeking to do is possible in shell. I'm trying to make a list of strings. The list will be looped through and each member of the list will be used to pass a parsing option to python. My script looks something like this: ... (3 Replies)
Discussion started by: Nacre
3 Replies

2. AIX

grep using lists?

I have a file that contain a list of files. How can I use grep to search the files in the list for a specific pattern? (2 Replies)
Discussion started by: bbbngowc
2 Replies

3. Shell Programming and Scripting

How to get the files lists

Hi All, Need the help in getting the file list which are generated for the time period. example if i want to get the list of file generated between 11 to 12 clock. i used the find command search the files with -cmin flag with -60. find /home/test/* -cmin -60 -type f -exec ls {} \; ... (2 Replies)
Discussion started by: nmadhuhb
2 Replies

4. Shell Programming and Scripting

Shell Script to Create non-duplicate lists from two lists

File_A contains Strings: a b c d File_B contains Strings: a c z Need to have script written in either sh or ksh. Derive resultant files (File_New_A and File_New_B) from lists File_A and File_B where string elements in File_New_A and File_New_B are listed below. Resultant... (7 Replies)
Discussion started by: mlv_99
7 Replies

5. Shell Programming and Scripting

Using foreach with two lists

Hi everybody, I'm trying to use a foreach command with two lists. The file.txt looks like this: var1: 100 200 300 var2: 3 6 9 I'm trying to use a foreach command to associate the two variables together. My script looks like this: #! /bin/tcsh set a=(`cat file.txt | grep 'var1' | cut -d... (8 Replies)
Discussion started by: SimonWhite
8 Replies

6. Shell Programming and Scripting

combining two lists

Hi, So I I received two lists for my merchandise and both are similar but differences do occur. I want to combine two lists that have similar names but I dont want the similar name to come up twice because I will end up purchasing two of those items. Heres an example below (file is massive). ... (1 Reply)
Discussion started by: kylle345
1 Replies

7. Shell Programming and Scripting

get the lists

I expert, I may cross post something similar but I dirtyed my quesion somehow to be clear in the thread #cat file1 88dee gcc: Grok for callconvention-hard to enable hard float a2ad2 eglibc: package mtrace separately 61487 python: bump PR of packages after update of distutils.bbclass... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

8. UNIX for Dummies Questions & Answers

Lists in awk

Hi togehter! I would like to write an awk script which prints the first column divided by the sum of the second column: So if this is my list 1 2 2 1 3 1 4 1 it should print a list like this: 1/5 2/5 3/5 4/5 My idea was to use END like this: (3 Replies)
Discussion started by: bjoern456
3 Replies

9. Shell Programming and Scripting

Issue with Lists

Hey guys, so I wrote this simple script. The first time I typed it all out, I had the issue where whatever choice I entered, it would simply tell me it was a "bad selection" aka the else output. I redid everything, and now no matter the choice, it does the backup option.. My brain hurts, and... (12 Replies)
Discussion started by: jakelawson44
12 Replies
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
This loop prints every value in a list together with the square and cube of the value: set values {1 3 5 7 2 4 6 8} ;# Odd numbers first, for fun! puts "Value Square Cube" ;# Neat-looking header foreach x $values { ;# Now loop and print... puts " $x [expr {$x**2}] [expr {$x**3}]" } 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)
All times are GMT -4. The time now is 08:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy