Sponsored Content
Full Discussion: Shell script foreach help
Top Forums UNIX for Dummies Questions & Answers Shell script foreach help Post 302711369 by dgrayman on Friday 5th of October 2012 10:50:34 PM
Old 10-05-2012
Error 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.
Code:
#!/bin/csh -fxv

if (! $#argv==1); then
    echo "[fail, not enough input arguments]"
    exit 10
else
    echo "the pitch and kinf will be stored in a new file called" $1
    echo " "
endif
rm $1

# uncompress output files in directory
set list= `/bin/ls *.out.gz`
foreach f ($list)
    gunzip $f
end

#run the pearl script on each output file and compress that file
set list= `/bin/ls *.out`
foreach i ($list)
    ./readfile.pl $i $1
    gzip $i
end

exit 0


Last edited by fpmurphy; 10-06-2012 at 12:38 AM..
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. Shell Programming and Scripting

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 ... (0 Replies)
Discussion started by: bonesy
0 Replies

4. 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

5. 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

6. Shell Programming and Scripting

expect ssh script issue with if and foreach

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)
Discussion started by: blahblahsomeone
0 Replies

7. Shell Programming and Scripting

foreach loop working in terminal but not in the script

Hi, I am new here I have used the forums a long time to search for things they are very helpful. I have unfortunately used up all my resources (professors, grad students) and need some help. I have this very simple piece of code (using to isolate the problem) in a csh script: #!/bin/csh... (12 Replies)
Discussion started by: bflinchum
12 Replies

8. Shell Programming and Scripting

foreach loop in unix script

Hi all, I have a script which searches for all sql files in the current directory and replaces all sql files with an underscore with a dash. The next part I need to do is record the number of changes made (underscore to dash) and display this value (e.g.2). This is what I have so far; find /... (17 Replies)
Discussion started by: shawi
17 Replies

9. 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

10. UNIX for Beginners Questions & Answers

Use foreach with sed in a bash script

I want to extract data from a ASCII file that looks like the one provided here (see input.txt). For this purpose I used sed commands. I want to chain the sed commands into a script that I can call with custom variables, instead of having to run it multiple times (Need to run the code for 30*24 =... (1 Reply)
Discussion started by: learningtocode
1 Replies
BP_PROCESS_WORMBASE(1p) 				User Contributed Perl Documentation				   BP_PROCESS_WORMBASE(1p)

NAME
process_wormbase.pl - Massage WormBase GFF files into a version suitable for the Generic Genome Browser SYNOPSIS
% process_wormbase.pl ./WS61 > wormbase.gff DESCRIPTION
This script massages the Wormbase GFF files located at ftp://www.wormbase.org/pub/wormbase/GENE_DUMPS into a version of the GFF format suitable for display by the generic genome browser. It mainly adds comments to the annotations and designates certain well-spaced genetic loci as framework landmarks. This script requires the AcePerl distribution, which is available on CPAN (look for the "Ace" module). To use this script, get the WormBase GFF files from the FTP site listed above and place them in a directory. It might be a good idea to name the directory after the current release, such as WS61. You do not need to uncompress the files. Then give that directory as the argument to this script and capture the script's output to a file: % process_wormbase.pl ./WS61 > wormbase.gff It may take a while before you see output from this script, since it must first fetch gene and protein database from the remote AceDB running at www.wormbase.org. The wormbase.gff file can then be loaded into a Bio::DB::GFF database using the following command: % bulk_load_gff.pl -d <databasename> wormbase.gff SEE ALSO
Bio::DB::GFF, bulk_load_gff.pl, load_gff.pl AUTHOR
Lincoln Stein <lstein@cshl.org> Copyright (c) 2002 Cold Spring Harbor Laboratory This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See DISCLAIMER.txt for disclaimers of warranty. perl v5.14.2 2012-03-02 BP_PROCESS_WORMBASE(1p)
All times are GMT -4. The time now is 05:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy