10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
hi,
OK. I am writing a bash script, and it is almost working for me.
Problem 1: I currently have stout sent to a file (stout.miRNA.bash.$date_formatted) which I would like to have work inside my loop, but when I move it, it just prints to the screen.
Problem 2: I have a second file... (18 Replies)
Discussion started by: hmortens
18 Replies
2. Shell Programming and Scripting
Sed command to replace a line in a file using line number from the output of a pipe.
Is it possible to replace a whole line piped from someother command into a file at paritcular line...
here is some basic execution flow..
the line number is 412
lineNo=412
Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies
3. Shell Programming and Scripting
Hi,
I want to read a live log file line by line and considering those line which start from time stamp;
Below code I am using, which read line but throws an exception when comparing line that does not contain error code
tail -F /logs/COMMON-ERROR.log | while read myline; do... (2 Replies)
Discussion started by: ketanraut
2 Replies
4. Shell Programming and Scripting
my requirement is,
consider a file output
cat output
blah sdjfhjkd jsdfhjksdh
sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf
hellow there
this doesnt look good
et cetc etc
etcetera
i want to replace a line of line number 4 ("this doesnt look good") with some other line
... (3 Replies)
Discussion started by: vivek d r
3 Replies
5. Shell Programming and Scripting
Hi How Are you?
I am doing fine!
I need to go now?
I will see you tomorrow!
Basically I need to replace the entire line containing "doing" with a blank line:
I need to the following output:
Hi How Are you?
I need to go now?
I will see you tomorrow!
Thanks in advance.... (1 Reply)
Discussion started by: sags007_99
1 Replies
6. Shell Programming and Scripting
Hi
Is there way to, say, echo a line and make sure it is always displayed on the first line, no matter what is coming out on stdout?
eg:
#!/bin/bash
clear
echo " ...... Internal audit script ......"
tar xvf hugefile.tar
I'd like to have the " Internal audit script " line to be shown... (2 Replies)
Discussion started by: bludhemn
2 Replies
7. Solaris
I get a file which has all its content in a single row.
The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file.
I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies
8. Shell Programming and Scripting
Hi all,
I got a file which contains this.
aaaaaaaaaaaaaaaaaaaaaaaa test
aaaaaaaaaaaaaa test
aaaaaaaaaaa test
aaaaaaaaaaaaaaaaa test
aaaaaaaaaaaaaaaaaaaaa test
aaaaaaaaa test
aaaaa test
and I want all test output in one row, ideally 3 spaces after the longest word.
Thanks (4 Replies)
Discussion started by: stinkefisch
4 Replies
9. Shell Programming and Scripting
Okay, title is kind of confusion, but basically, I have a lot of scripts on a server that I need to replace a ps command, however, the new ps command I'm trying to replace the current one with pipes to sed at one point. So now I am attempting to create another script that replaces that line.
... (1 Reply)
Discussion started by: cbo0485
1 Replies
10. UNIX for Dummies Questions & Answers
Is it possible to redirect errors at the command line when you run the script such as bash scriptname & 2>/dev/null? (1 Reply)
Discussion started by: knc9233
1 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)