10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
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
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. Shell Programming and Scripting
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
4. Shell Programming and Scripting
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
5. Shell Programming and Scripting
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
6. UNIX for Dummies Questions & Answers
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)
Discussion started by: moldoverb
3 Replies
7. Shell Programming and Scripting
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. I'm doing this in tcsh
This works fine to do the search:
while read i; do grep $i file2; done <file1.txt
This also works fine to read a directory:
foreach file ('/bin/ls... (1 Reply)
Discussion started by: moldoverb
1 Replies
8. UNIX for Dummies Questions & Answers
Suppose I have a script named "sc.sh"
in the script how to print out its name "sc.sh"? (3 Replies)
Discussion started by: meili100
3 Replies
9. UNIX for Dummies Questions & Answers
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
10. UNIX for Dummies Questions & Answers
Hello, I am new at this forum so please bare with me on this.
Within a given directory, I have a list of files in which in each file, I would like to do a substitution. I would like to substitute the string mlcl to mll in each file using the foreach command. I dont quite get how to do that. If... (7 Replies)
Discussion started by: clipski
7 Replies