Aswex
1
Hello,
I need help to add a # dynamically to a .txt file that contain files location
I called the file listing.txt
Dir1/Dir2/file_name
Here is what I am trying to do.
I am using a short shell ksh script on solaris. I am using a loop to read this log file line by line.
And then retrieve file from an archive system.
for lines in `cat linsting.txt` ;
do
As a have a huge amont of files to retrieve, if I lost the connection to the archive system it's hard for me to easly find where to restart.
So my idea is to had something in front of each line for each file that I successfully retrieve.
In that way I may be able to grep to the first line without the #
Thanks for your help
styno
2
why don't you just populate a seperate file?
for file in `cat list`
do
... get the file
if [ $? -eq 0 ]
then echo #$file >> list2
fi
done
aigles
3
You can do something like that :
$ cat aswex.ksh
FileList=./aswex.dat
LastFile=./aswex.dat.last
touch ${LastFile}
(( last = $(<${LastFile}) + 0 ))
print "Starting from line $((last+1))"
awk 'NR>rec' rec=${last} ${FileList} |
while read file
do
print "Processing file ${file} ..."
sleep 5
print "Ok."
(( last += 1 ))
echo ${last} > ${LastFile}
done
print "Done."
$ cat aswex.dat
file1
file2
file3
file4
file5
file6
$ rm aswex.dat.last
$ ./aswex.ksh
Starting from line 1
Processing file file1 ...
Ok.
Processing file file2 ...
Ok.
Processing file file3 ...
^C$ cat aswex.dat.last
2
$ ./aswex.ksh
Starting from line 3
Processing file file3 ...
Ok.
Processing file file4 ...
Ok.
Processing file file5 ...
Ok.
Processing file file6 ...
Ok.
Done.
$ ./aswex.ksh
Starting from line 7
Done.
$
Jean-Pierre.
1 Like
Aswex
4
Dear Jean-Pierre,
thanks a lot for your help. Your code is working great. If I may I have another question ..
The archive system may return error message sometimes. I know how to catch shell retrun code but here it's more a message than a value.
It could be for exemple :
RC = 21 USER NOT CONNECTED
Do you know how I could catch this message to end the script ?
any idea ?
I am thinking about something like this :
if [ $file != $file ]
Thanks again for your help