Script to do a function on all files in one run

Hello everybody
I am trying to write a script in Cshell solaris 8 to read a number of files and do some commands on them (for example extracting some information) and send the results to one single file. I want to do that for all the files in one run. Could any body advise me on it.
Thanks and Regards
Reza

Can you be more specific about the commands you are going to perform.

for file in *.txt
do
something on $file >>output.file
done

The output file is appended with all the results of the commands.

Before you get into the loop you might also want to initialize the file first:

cat /dev/null > output.file

or you may have the results of the previous run in your output file too!

Thanks for your helps
Do loop is OK but I don't know if I can introduce an array as a series of variables trough a file or by keyboard. As a simple example I want to cut few lines of each file in a directory and put it in a seperate file in the same directory.
1-Is it possible to introduce the file names as a variable to the program and
2- How can I write a script which will ask me the input value as a variable. So I can type the variable name and it will run the command on the variable (like a file name)?

Best Regards
Reza

Reza.

How much do you know about shell scripting? Those are basic questions. You may do well to do some reading on Bourne, Korn and C shells in Unix. A simple search on the Internet should turn up some useful pages. Use keywords like "Bourne" "Korn" "C Shell" "Unix" "Scripting" or "Tutorial".

  1. In Bourne and Korn shell you can define a variable at any time by assigning a value to it:

MYVAR=some_value

Note there are no spaces around the '=' sign and the variable name is upper case by convention.

You may return the value of a variable by preceding the name with a dollar sign:

echo $MYVAR

A script may also receive parameters from the command line in variables $1, $2 ... $9.

e.g

echo $5

would return the 5th command line argument.

So:

MY_FILE=/tmp/output.txt

cat /dev/null > $MY_FILE

or ...

cp $3 $MYFILE.old

Ok. Theres a start with shell script variables. Find out what more you can do with them.

  1. To obtain a value from the user use the 'read' command. This command is built into the shell and should always be availalbe to you:

read MY_FILE

The user must enter their value followed by a carriage return, before the value is committed to the variable.

You may then access the value in the variable as before:

echo $MY_FILE

I have given you a very brief and limited overview of Bourne/Korn shell variables, but I really do recommend that you do some futher reading on this topic.

Hope this helps.

MBB

Thanks Gents
I will practice much more on it. And thanks for your useful advises.
Best regards
Reza