Modify different files at the same time

Hi, I'm having the following problem.
I have some files to modify, between a large number of files.
I thought the following code

aux2=`grep -l 2.2.17 *`
print "$aux2"
aux3=`ls -l *.ksh | wc -l`
print "$aux3"

while [  $aux3 -ne 0 ]; do
        print "The counter is $aux3"
        #Add the sed here
        aux3=$((aux3-1))
done

I also thought the basic code for the modify. I have to use a sed :stuck_out_tongue:
But I don't know how to go between the different files in the while. Use the first file in the first loop, the second file in the following loop and so on.
The files are stored in the aux2 variable.

Could you give me any idea

Thanks

What's your system? What's your shell?

You don't need -l if you're just counting the lines. ls always prints single-column if you're piping its output.

I'm confused what that count is for or why you get it in such a manner.

If you have linux, you can sed many files in-place with -i:

aux3=`ls *.ksh | wc -l`
# Only split on newlines.  Otherwise, spaces in filenames
# may mess up aux2.
IFS="
"
aux2=`grep -l 2.2.17 *`
whille [ "$aux3" -gt 0 ]
do
        sed -i "s/a/b/g" $aux2 # DO NOT QUOTE aux2.  It will split on newlines.
done

If you don't have sed -i:

aux3=`ls *.ksh | wc -l`
# Only split on newlines.  Otherwise, spaces in filenames
# may mess up aux2.
IFS="
"
aux2=`grep -l 2.2.17 *`
whille [ "$aux3" -gt 0 ]
do
        for FILE in $aux2
        do
                sed 's/a/b/g' < "$FILE" > /tmp/$$
                cat /tmp/$$ > "$FILE"
        done
done

If you explain exactly what you're trying to accomplish instead of the manner you wish to do it, there's probably much better ways than running sed n*m times for each file.

Thanks for the quick answer.
I'm working on a RedHat.
I think I miss some explanation, inside aux2 you have all the filename of the files I need to change. And inside aux3 you have the number of files.
For example:
Inside aux2 you have:
log_cleanup.ksh
logs_gzip.ksh
logs_move.ksh
Inside aux3 you have: 3 (the number of file)

---------- Post updated 09-22-11 at 12:19 AM ---------- Previous update was 09-21-11 at 09:31 PM ----------

The script works perfect, but there is one thing. Instead of replace, I need to append to the end of each file

aux3=`ls *.ksh | wc -l`
# Only split on newlines.  Otherwise, spaces in filenames
# may mess up aux2.
IFS="
"
aux2=`grep -l 2.2.17 *`

print "AUX3 --> $aux3"
print "AUX2 --> $aux2"

while [ "$aux3" -gt 0 ];
do
        sed -i "s/2.2.17/2.2.21/g" $aux2 # DO NOT QUOTE aux2.  It will split on newlines.
        aux3=$((aux3-1))
done

I clear it a little to work with my script

I think the loop's pointless, then, since you edit the same files the same way every single loop. That also makes it a useless use of backticks and a useless use of ls *.

You can loop over the files without backticks, ls, or arithmetic:

for FILE in *.ksh
do
        # Append the line 'something' to the file
        echo "something" >> "$FILE"
done