Hi Code gurus!!...my first post in this forums and I m new to shell scripting too!...I need a shell script to accomplish the below, any input will be greatly appreciated..

Below is a sample content of a text file, file1.txt


AMPS,2324,Subscriber,Unknown,SingleDay,20070413,20070413,

ALPEnt,4516,AllMember,Unknown,DateRange,20070411,20070419,

AGLT,2156,Summary,Unknown,

DUPP,2536,Yes,Unknown,

My current UNIX script reads the file (file1.txt) line by line- each line calls various scripts (to generate reports) depending on the first parameter that is passed. These text files can sometime reach as many as 50 lines (meaning 50 reports have to be generated). Sometimes the process cannot complete. Let us say, for example, the process fails on line 22 (meaning 21 reports were generated and another 29 were not). When I restart the shell script, I want it to be able to start from line 22 and not from the beginning. One solution is to copy each line for which the report is generated, to a temp file (file1_temp.tmp). If the process fails in between, the script does a count on the number of lines present in temp file (file1_temp.tmp) and then continues to generate report from file1.txt based on the count obtained.

I need a script to accomplish the following:

1) Create a file: file1_temp.tmp
2) Do a count on number of lines in file1_temp.tmp
3) Start reading the line number obtained in step 2 from original file, file1.txt and generate reports (initially the count will be zero and hence will read file from the first line)
4) Once the report is complete, copy the line from file1.txt to file1_temp.tmp
5) Once the whole file is processed, delete both, file.txt and file1_temp.tmp


PLEASE HELP ME OUT HERE!

Thanks!

1) touch file1_temp.tmp
2) reports_done = `wc -l file1_temp.tmp`
3+4) I do not have a terminal in front of me, run a for loop sounds easy.

# read in file1.txt to variable $lines
lines=`cat file1.txt`
# set local line count variable to 0
count=0
for line in $lines
do
  # if $count > $reports_done = we have not run this fella yet!
  if [ $count -gt $reports_done ]
  then
    report_to_run=$line
    # CODE TO RUN REPORT GOES HERE
    echo "Ran report: $report_to_run" >> file1_temp.tmp
  fi
  # increment $count by 1 (count++; if only)
  count=`expr $count + 1`
done

5) rm -rf file1.txt file1_temp.tmp

thanks a bunch Stylish!...i will try to run it n keep u posted:)

for some strange reason I cant use IFS in this code?? I want to read the second variable in the comma seperated line but it gives error... any suggestion??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.