#!/bin/bash
foreach x (67402996 67402998)
{
grep -a x FINAL2006.dat >> MISSING_RECORDS.dat
}
I'm trying to pass a list to the variable x, and then grep for that string in FINAL2006.dat...
Final2006.dat is in the same folder as my .sh file. I call this with a .cmd file...
At any rate,... (6 Replies)
Hi,
I'm having a small issue here and I can't get it to work. I'm programming a script for bash and I need to do something to all the folder in a directory. So I'm in the directory and I want to use the foreach statement but I dont know how to reference all the folders of that directory. To make... (7 Replies)
Hi Guys,
I have a loop which uses a wildcard
i.e. foreach f (*)
but when I execute the tcsh file in unix then it gives me an error
->>>>>>>foreach: words not parenthesized<<<<<<<<<<-
Any help. (1 Reply)
Hi everyone
Does anyone know what is wrong with this script. i keep getting errors
foreach filename (`cat testing1`)
set string=$filename
set depth=`echo "$string"
echo $depth
end
the error is the following
testing: line 1: syntax error near unexpected token `('
testing: line 1:... (3 Replies)
OK, so I am extremely rusty and am just getting back to Unix after 9 years.
I'm stuck on something easy. I want to search line-by-line for a string in a file, and I want to do this to a series of files in a directory.
This works fine to do the search:
while read i; do grep $i file2; done... (3 Replies)
Hi,
I am trying to create an ssh script to login to cisco routers and activate/deactivate bgp neighbors if they match certain conditions. I dont think my "if" and "foreach" are working correctly. Any help is appreciated. Below is my script:
... (0 Replies)
I have a foreach loop in a csh script and I noticed that it tries to find the files with the pattern *$searchpt* in the file name. I'm confused as I never specified checking for the files.
foreach f ( *$searchpt* )
set fnew = `echo $f | awk -v searchpat=$searchpt \
... (1 Reply)
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)
Hello Everyone,
I have the following codes that only works for the first login element. I can't get it work with the second and third login credentials. Can anyone here see the problem?
I ran the code with host1, it works as expect. see below:
# ./test.pl host1
Trying to connect... (3 Replies)
Perl::Critic::Policy::Variables::RequireLexicalLoopIteraUser(Contributed Perl DocPerl::Critic::Policy::Variables::RequireLexicalLoopIterators(3pm)NAME
Perl::Critic::Policy::Variables::RequireLexicalLoopIterators - Write "for my $element (@list) {...}" instead of "for $element (@list)
{...}".
AFFILIATION
This Policy is part of the core Perl::Critic distribution.
DESCRIPTION
This policy asks you to use "my"-style lexical loop iterator variables:
foreach my $zed (...) {
...
}
Unless you use "my", "for"/"foreach" loops use a global variable with its value "local" to the block. In other words,
foreach $zed (...) {
...
}
is more-or-less equivalent to
{
local $zed
foreach $zed (...) {
...
}
}
This may not seem like a big deal until you see code like
my $bicycle;
for $bicycle (@things_attached_to_the_bike_rack) {
if (
$bicycle->is_red()
and $bicycle->has_baseball_card_in_spokes()
and $bicycle->has_bent_kickstand()
) {
$bicycle->remove_lock();
last;
}
}
if ( $bicycle and $bicycle->is_unlocked() ) {
ride_home($bicycle);
}
which is not going to allow you to arrive in time for dinner with your family because the $bicycle outside the loop is not changed by the
loop. You may have unlocked your bicycle, but you can't remember which one it was.
Lexical loop variables were introduced in Perl 5.004. This policy does not report violations on code which explicitly specifies an earlier
version of Perl (e.g. "require 5.002;").
CONFIGURATION
This Policy is not configurable except for the standard options.
SEE ALSO
"Foreach Loops" in perlsyn
"my() in Control Structures" in perl5004delta
AUTHOR
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
COPYRIGHT
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license
can be found in the LICENSE file included with this module.
perl v5.14.2 2012-06-07 Perl::Critic::Policy::Variables::RequireLexicalLoopIterators(3pm)