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
libppl_c(3)							 libppl_c overview						       libppl_c(3)

NAME
libppl_c - the C interface of the Parma Polyhedra Library SYNOPSIS
#include <ppl_c.h> cc file.c -lppl DESCRIPTION
This is a short overview on how to use the Parma Polyhedra Library (PPL) in your C programs on Unix-like operating systems. Note that the PPL has interfaces also for C++, Java, OCaml and a number of Prolog systems: look elsewhere for documentation on those. Note also that the present document does not describe the library functionality, its classes or its methods and functions: see The Parma Polyhedra Library User's Manual (version 0.11.2) and The Parma Polyhedra Library C Language Interface User's Manual (version 0.11.2) for this kind of infor- mation. INCLUDING THE HEADER FILE
The C interface of the PPL has only one header file, named ppl_c.h. So your program should contain a directive of the form #include <ppl_c.h> Of course, you must make sure you installed the PPL in a place where the compiler can find it, either by itself or with the help of a suit- able -Idir command line option (see the file INSTALL for information on how to configure the library so that it is installed in the place of your choice). INITIALIZING AND FINALIZING THE LIBRARY
In order to initialize the Parma Polyhedra Library you must call the function int ppl_initialize(void) before using any of its functionalities. It is also a good norm to call the function int ppl_finalize(void) when you are done with the library. USING THE LIBRARY
Keeping in mind that there is no substitute for a careful reading of The Parma Polyhedra Library User's Manual (version 0.11.2) and The Parma Polyhedra Library C Language Interface User's Manual (version 0.11.2) you can find examples of use in the directories inter- faces/C/tests and demos/ppl_lpsol of the source distribution. LINKING WITH THE LIBRARY
Linking with the C interface of the Parma Polyhedra Library is best done using the C compiler itself: usually, specifying the -lppl_c com- mand line option is enough. In fact, if you use a shared version of the library, this automatically records the dependency from the PPL core and the GMP libraries, something that the linker ought to deal with gracefully. Otherwise you will have to add -lppl -lgmpxx -lgmp to the command line. Things are more complex if you installed the PPL into some nonstandard place. In this case you will have to use the -Ldir option and, if you use a shared version of the library, possible take further steps: see the documentation of your system for more information on this subject (the Program Library HOWTO is especially valuable for GNU/Linux users). RETURN VALUES
All the PPL C interface functions return an int: a negative value means that an error occurred. See The Parma Polyhedra Library C Language Interface User's Manual (version 0.11.2) for the error codes. IMPLEMENTING MEMORY-GUARDED COMPUTATIONS One of the interesting features of the Parma Polyhedra Library is the possibility to implement memory-guarded computations. The idea is that you can limit the amount of virtual memory available to the process, launch a PPL computation, and be ready to be returned a PPL_ERROR_OUT_OF_MEMORY error code. You can then take the appropriate corrective measures (e.g., simplify the polyhedra and/or select less precise though less complex algorithms), and restart the computation. In order to do that, you should define alternative memory allocation functions for GMP that throw std::bad_alloc upon memory exhaustion. See libppl(3) for instructions on how to do that. USING NATIVE FLOATING POINT NUMBERS
At initialization time, the Parma Polyhedra Library sets the FPU rounding mode in a way that allows its floating-point-based computations to be conservative (i.e., possibly approximated but correct) and reasonably efficient. In case your application itself uses native float- ing point numbers and relies on a particular rounding mode (if you are in doubt, assume that it does rely on round-to-nearest to be in effect), you should use the function int ppl_restore_pre_PPL_rounding() after the PPL initialization and before using native floating point numbers in the application. If your application does not use any floating-point-based PPL abstraction, no further measure should be taken. Otherwise, it is imperative to call the function int ppl_set_rounding_for_PPL() before invoking any PPL interface related to such abstractions. SEE ALSO
ppl-config(1) libppl(3) Roberto Bagnara, Patricia M. Hill, and Enea Zaffanella. The Parma Polyhedra Library User's Manual (version 0.11.2), available (in several formats) at http://www.cs.unipr.it/ppl/ . Roberto Bagnara, Patricia M. Hill, and Enea Zaffanella. The Parma Polyhedra Library C Language Interface User's Manual (version 0.11.2), available (in several formats) at http://www.cs.unipr.it/ppl/ . David A. Wheeler. Program Library HOWTO, available (in several formats) at http://www.dwheeler.com/program-library/ . AVAILABILITY
The latest version of the Parma Polyhedra Library and all the documentation is available at http://www.cs.unipr.it/ppl/ . AUTHOR
See the file CREDITS in the source distribution or use the command ppl-config --credits for a list of contributors. REPORTING BUGS
Report bugs to <ppl-devel@cs.unipr.it>. COPYRIGHT
Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it> Copyright (C) 2010-2011 BUGSENG srl (http://bugseng.com) This is free software; see the file COPYING in the source distribution or use the command ppl-config --copying to obtain the copying condi- tions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. PPL 0.11.2 February 2011 libppl_c(3)