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::RadioMenuItem(3)					User Contributed Perl Documentation				    Gtk2::RadioMenuItem(3)

NAME
Gtk2::RadioMenuItem HIERARCHY
Glib::Object +----Glib::InitiallyUnowned +----Gtk2::Object +----Gtk2::Widget +----Gtk2::Container +----Gtk2::Bin +----Gtk2::Item +----Gtk2::MenuItem +----Gtk2::CheckMenuItem +----Gtk2::RadioMenuItem INTERFACES
Glib::Object::_Unregistered::AtkImplementorIface Gtk2::Buildable Glib::Object::_Unregistered::GtkActivatable METHODS
widget = Gtk2::RadioMenuItem->new ($member_or_listref=undef, $label=undef) o $member_or_listref (scalar) o $label (string) widget = Gtk2::RadioMenuItem->new_from_widget ($group, $label=undef) o $group (Gtk2::RadioMenuItem) o $label (string) Since: gtk+ 2.4 widget = Gtk2::RadioMenuItem->new_with_label ($member_or_listref=undef, $label=undef) o $member_or_listref (scalar) o $label (string) widget = Gtk2::RadioMenuItem->new_with_label_from_widget ($group, $label=undef) o $group (Gtk2::RadioMenuItem) o $label (string) Since: gtk+ 2.4 widget = Gtk2::RadioMenuItem->new_with_mnemonic ($member_or_listref=undef, $label=undef) o $member_or_listref (scalar) o $label (string) widget = Gtk2::RadioMenuItem->new_with_mnemonic_from_widget ($group, $label=undef) o $group (Gtk2::RadioMenuItem) o $label (string) Since: gtk+ 2.4 list = $radio_menu_item->get_group Returns a list of Gtk2::RadioMenuItems, the group. $radio_menu_item->set_group ($member_or_listref) o $member_or_listref (scalar) PROPERTIES
'group' (Gtk2::RadioMenuItem : writable / private) The radio menu item whose group this widget belongs to. SIGNALS
group-changed (Gtk2::RadioMenuItem) SEE ALSO
Gtk2, Glib::Object, Glib::InitiallyUnowned, Gtk2::Object, Gtk2::Widget, Gtk2::Container, Gtk2::Bin, Gtk2::Item, Gtk2::MenuItem, Gtk2::CheckMenuItem 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::RadioMenuItem(3)