Shell Integer with nested foreach


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Integer with nested foreach
# 1  
Old 04-30-2009
Shell Integer with nested foreach

I am scripting in tcsh and here is what I currently have:

foreach group (g1 g2 g3 g4)
set ppl = `cat $group.file.with.list.of.ppl.in.row.format`
set label = 1
@ label += 1
foreach ppls ($ppl)
echo $label >> file
end
end


Essentially for each ppl(s) per group, I would like to have the same number label in a file with ppl(s) from different groups. That is if each group had 5 ppl(s), the file would have 5 lines of 1s, 5 lines of 2s, 5 lines of 3s, etc. However, for some reason I am not getting the integer to add properly. I expect it is because the imbedded foreach. How can I remedy this? Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Foreach alternative - C shell

Hi all I wrote a foreach loop in c-shell: foreach file (/.../fileNames*) ... end The problem is that if there aren't matching files in the directory I'm getting a "foreach: No match". How can I rewrite it so the script will just skip the loop if there aren't any matching files? ... (4 Replies)
Discussion started by: Somename
4 Replies

2. UNIX for Dummies Questions & Answers

Shell script foreach help

I am writing a shell script to uncompress files in a directory, then call a Perl script to search the files for given terms, store those terms in a different output file , and compress the output. I get a syntax error with my use of foreach. Below is my script. #!/bin/csh -fxv if (!... (2 Replies)
Discussion started by: dgrayman
2 Replies

3. UNIX for Dummies Questions & Answers

Executing nested loops+foreach

It's been a while since I used csh formatting and I am having a little bit of trouble with a few things. Things seem so much easier to execute in Matlab, however I need to do this on the terminal because of the programs I am trying to interact with. So here's what I want to do: I have a file... (0 Replies)
Discussion started by: katia
0 Replies

4. Shell Programming and Scripting

Shell script: foreach file -> targzip

Hi there, I need some help with a shell script (I'm no sh script expert, but I hope this will explain how I want my script):dir = /home/user/files/ foreach(*.jpg file in $dir) { tar -cf $file(-.jpg).tar $file;gzip $file(-.jpg).tar } mv -f $dir*tar.gz /home/user/pictures/ Thanks for any... (12 Replies)
Discussion started by: JKMlol
12 Replies

5. Shell Programming and Scripting

Nested foreach in perl

I have two arrays @nextArray contains some files like \main\1\Xul.xml@@\main\galileo_integration_sjc\0 \main\1\PortToStorageDialog.xml@@\main\galileo_integration_sjc\0 . . . \main\1\PreferencesDialog.xml@@\main\galileo_integration_sjc\0 @otherArray contains some files like ... (2 Replies)
Discussion started by: nmattam
2 Replies

6. UNIX for Dummies Questions & Answers

foreach shell question

Hi I would like foreach to go through a range of numbers 1-365. This input is being read by a compiled fortran program in the same shell script. Let me try an example to clarify #!/bin/sh foreach i (1-365) ./data_make program <<EOF 'echo $i' /data_'echo $i' #output file I... (10 Replies)
Discussion started by: d_kowalske
10 Replies

7. Shell Programming and Scripting

C Shell - foreach - No Match error

Hi All, I am facing 'No Match' problem with foreach loop in C shell script. Initially I tried following grep command showing results properly as shown at the end of the Thread. But foreach command is throwing the error 'No match'. grep -n Inserted audit_file foreach insertstr (`grep -n... (0 Replies)
Discussion started by: adurga
0 Replies

8. Shell Programming and Scripting

Shell nested ifs

Hi can someone tell me whats wrong with the following: #!/bin/sh file1=$1 file2=$2 if then if then echo "File 1 is" $file1 echo "File 2 is" $file2 cp $file1 $file2 echo "Copy complete!" else echo "ERROR: File does not exist!" ... (8 Replies)
Discussion started by: philmetz
8 Replies

9. UNIX for Dummies Questions & Answers

foreach in shell scripting

I need to read list of machines from a file using foreach loop. I am trying the follwing, but its not reading the list foreach i (`cat file.lst | awk '{print $1}'`) ls -l | grep $i end here the file file.lst contains list of files Any idea whats wrong here Thanks Krisyet (2 Replies)
Discussion started by: krisyet
2 Replies
Login or Register to Ask a Question
Gtk2::RadioButton(3)					User Contributed Perl Documentation				      Gtk2::RadioButton(3)

NAME
Gtk2::RadioButton SYNOPSIS
# first group $foo1 = Gtk2::RadioButton->new (undef, 'Foo One'); $foo2 = Gtk2::RadioButton->new ($foo1, 'Foo Two'); $foo3 = Gtk2::RadioButton->new ($foo2, 'Foo Three'); # second group, using the group reference $bar1 = Gtk2::RadioButton->new (undef, 'Bar One'); $group = $bar1->get_group; $bar2 = Gtk2::RadioButton->new ($group, 'Bar Two'); $bar3 = Gtk2::RadioButton->new ($group, 'Bar Three'); # move bar3 from the bar group to the foo group. $bar->set_group ($foo->get_group); # iterate over the widgets in the group $group = $foo1->get_group; foreach my $r (@$group) { $r->set_sensitive ($whatever); } DESCRIPTION
A single radio button performs the same basic function as a Gtk2::CheckButton, as its position in the object hierarchy reflects. It is only when multiple radio buttons are grouped together that they become a different user interface component in their own right. Every radio button is a member of some group of radio buttons. When one is selected, all other radio buttons in the same group are deselected. A Gtk2::RadioButton is one way of giving the user a choice from many options; Gtk2::OptionMenu and Gtk2::ComboBox (added in gtk+ 2.4) are alternatives. Each constructor can take either a group or widget from that group where the group is wanted; this is an enhancement over the C API. Nevertheless, the _from_widget forms are provided for completeness. HIERARCHY
Glib::Object +----Glib::InitiallyUnowned +----Gtk2::Object +----Gtk2::Widget +----Gtk2::Container +----Gtk2::Bin +----Gtk2::Button +----Gtk2::ToggleButton +----Gtk2::CheckButton +----Gtk2::RadioButton INTERFACES
Glib::Object::_Unregistered::AtkImplementorIface Gtk2::Buildable Glib::Object::_Unregistered::GtkActivatable METHODS
widget = Gtk2::RadioButton->new ($member_or_listref=undef, $label=undef) o $member_or_listref (scalar) reference to radiobutton group or a Gtk2::RadioButton belonging to that group. o $label (string) Create a radio button. If $label is provided, it will be interpreted as a mnemonic. If $member_or_listref is undef, the radio button will be created in a new group. widget = Gtk2::RadioButton->new_from_widget ($group, $label=undef) o $group (Gtk2::RadioButton or undef) o $label (string) widget = Gtk2::RadioButton->new_with_label ($member_or_listref=undef, $label=undef) o $member_or_listref (scalar) reference to radiobutton group or a Gtk2::RadioButton belonging to that group. o $label (string) Create a radio button with a plain text label, which will not be interpreted as a mnemonic. widget = Gtk2::RadioButton->new_with_label_from_widget ($group, $label=undef) o $group (Gtk2::RadioButton or undef) o $label (string) widget = Gtk2::RadioButton->new_with_mnemonic ($member_or_listref=undef, $label=undef) o $member_or_listref (scalar) reference to radiobutton group or a Gtk2::RadioButton belonging to that group. o $label (string) Create a radio button with a mnemonic; this is an alias for "new". widget = Gtk2::RadioButton->new_with_mnemonic_from_widget ($group, $label=undef) o $group (Gtk2::RadioButton or undef) o $label (string) $group = $radio_button->get_group Return a reference to the radio group to which $radio_button belongs. The group is a reference to an array of widget references; the array is not magical, that is, it will not be updated automatically if the group changes; call "get_group" each time you want to use the group. $radio_button->set_group ($member_or_listref) o $member_or_listref (scalar) reference to the group or a Gtk2::RadioButton belonging to that group. Assign $radio_button to a new group. PROPERTIES
'group' (Gtk2::RadioButton : writable / private) The radio button whose group this widget belongs to. SIGNALS
group-changed (Gtk2::RadioButton) SEE ALSO
Gtk2, Glib::Object, Glib::InitiallyUnowned, Gtk2::Object, Gtk2::Widget, Gtk2::Container, Gtk2::Bin, Gtk2::Button, Gtk2::ToggleButton, Gtk2::CheckButton COPYRIGHT
Copyright (C) 2003-2008 by the gtk2-perl team. This software is licensed under the LGPL. See Gtk2 for a full notice. perl v5.12.1 2010-07-05 Gtk2::RadioButton(3)