Add # dynamically to log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add # dynamically to log file
# 1  
Old 07-01-2011
Add # dynamically to log file

Hello,

I need help to add a # dynamically to a .txt file that contain files location

I called the file listing.txt

Code:
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.


Code:
  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
# 2  
Old 07-01-2011
why don't you just populate a seperate file?

Code:
for file in `cat list`
do
   ... get the file
   if [ $? -eq 0 ]
    then echo #$file >> list2
   fi
done

# 3  
Old 07-01-2011
You can do something like that :
Code:
$ 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.
This User Gave Thanks to aigles For This Post:
# 4  
Old 07-04-2011
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 :

Code:
 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 :

Code:
if [ $file != $file ]

Thanks again for your help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Dynamically split file

Hi guys, I have a file with 10000 entries (there are 2 columns. the first column contains the the product name and the second column contains the quantity of each product). I would like to split this file into 5 different files. I want the 1st entry to go to the fileA the 2nd entry to fileB... (3 Replies)
Discussion started by: coweb
3 Replies

2. UNIX for Advanced & Expert Users

Dynamically add paths to inotify

I have initiated an inotify process with --fromfile option and the file contain the paths to be monitored. /usr/local/maldetect/inotify/inotifywait -d -r -o /usr/local/maldetect/inotify/inotify_log --fromfile /usr/local/maldetect/sess/inotify.paths.28364 --exclude (^/var/tmp/mysql.sock)... (2 Replies)
Discussion started by: anil510
2 Replies

3. Shell Programming and Scripting

Dynamically creating file names from portions of another file name

Not sure how to do the following, but any help would be appreciated. Has to be done using C shell (sorry about that). I have about 300 files that I need this done for, but I am only going to give one example. I will just need to know how to execute your solution through some type of loop to get... (2 Replies)
Discussion started by: jclanc8
2 Replies

4. Shell Programming and Scripting

Shell Script to Dynamically Extract file content based on Parameters from a pdf file

Hi Guru's, I am new to shell scripting. I have a unique requirement: The system generates a single pdf(/tmp/ABC.pdf) file with Invoices for Multiple Customers, the format is something like this: Page1 >> Customer 1 >>Invoice1 + invoice 2 >> Page1 end Page2 >> Customer 2 >>Invoice 3 + Invoice 4... (3 Replies)
Discussion started by: DIps
3 Replies

5. UNIX for Dummies Questions & Answers

Read a file dynamically

Hi my requriment is read the file name dynamically my code is #!/bin/sh file="/c/work/loan/" Header_Trailer_move() { sed '1d;$d' $file| cat >sam.txt } Header_Trailer_move in above given path my list of files or there i have to read file dyanamically when i entered particular file name... (2 Replies)
Discussion started by: sgoud
2 Replies

6. Shell Programming and Scripting

Need to dynamically create a file

I'm trying to write a script that generates a file of varying size filled with random text and am having some difficulties. The major problems are that I'm limited to csh and a lot of the systems I have to run this on don't have a /dev/random (so a wrapper around the dd if=/dev/random or dd... (14 Replies)
Discussion started by: stareja
14 Replies

7. Shell Programming and Scripting

Dynamically locating a file

Hi, I have a requriement where in I need to install a s/w by executing the installable file through a script. The script currently contains the path of the installable file. I need to now update the script accordingly such tht it identifies the location of the installable file automatically and... (1 Reply)
Discussion started by: yoursdavinder
1 Replies

8. Shell Programming and Scripting

Spliting the file dynamically

i am creating the file , when this file reaches the size 2 GB, i need one message or fire (4 Replies)
Discussion started by: kingganesh04
4 Replies

9. UNIX for Advanced & Expert Users

dynamically linked file

Hi friends, i have a dynamically linked file on my solaris system.this is script that runs regularly. How can i read the contents of that ? when i tried to say "vi filename " then it says executable and nothing is seen. Please help. thanks in advance Veera (5 Replies)
Discussion started by: sveera
5 Replies

10. Shell Programming and Scripting

dynamically linked file

Hi friends , how do i view a dynamically linked file in unix ? its there on other system and do i have to ftp it in ASCII format or binary ? and after the ftp how do i view it ? thanks in advance veeras (1 Reply)
Discussion started by: sveera
1 Replies
Login or Register to Ask a Question