Hi,
Here is a big head scratcher for me....
I'm creating a loop with while reading lines from a file called example.txt:
#!/bin/sh
while read line
do
some command > another file ----- output to another file
done < example.txt
I would like that another file to be unique for every line executed
Is that possible at all?
thanks all
Hi,
you can achieve that using the $RANDOM variable appending to the file name
you can check the random variable exists in your setup or not
$ print $RANDOM $RANDOM
29302 8082
it will generate two different number that means it support that
now u can create a file with filename."_"$RANDOM
thanks,
venkat
Unfortunately it does not support it...
Hi,
then do with filename appending with date
$ date +'%m%d_%H%M%S'
0124_120358
like filename.""`date +'%m%d%H%M%S'`
ex:-
$ echo "filename"_"`date +'%m%d_%H%M%S'`"
filename_0124_120542
thanks,
venkat
I think it is my fault not explaining myself very well.
The file name should be different but from a range of predefined values.
As an example the filenames may be contained in another file and each file1 be called on first loop, file2 on second etc.
Or you could also use a counter:
c=1
while read line
do
command > file_$c
c=$(($c + 1))
done < example.txt