Bash script to read a file from particular line till required line and process

Hi All,

Am trying to write wrapper shell/bash script on a utility tool for which i need to pass 2 files as arugment to execute utility tool.

Wraper script am trying is to do with above metion 2 files.

utility tool accepts :
a. userinfo file : which contains username
b. item file : which contains items to be processed by mentioned users from userinfo file.

Below script works fine for userfile and itemfile

Am thinking of writing a wrapper script which call this script but in the wapper script it should execute utility tool from specified lines to perticular line from userfile and even for itemfile.

for ex : say userfile has 100 users and itemfile has 1000 items. so, i should call the wrapper script with passing argument saying run script for users from line 20-45 from userfile and say item from line 250-400 from itemfile.

basically it should run the utility tool from specified user number to a specfied item numbers.

#!/bin/bash

#echo "***********************************************"

count=1
userFile=$1

if [ -f $userFile ]; then
 echo "userfile exist"
else
 echo "user file $userFile do not exit, exiting !!!"
 exit 1
fi

for user in ` cat $userFile ` ; do
./dmstool -S rms -h 10.212.45.67 -f /tmp/itemfile -m -u $user
   #sleep 5
    echo "Completed - user $count"
   (( count=$count+1 ))
done

Any help will be much appreciated.

Thanks

I guess this is it :cool: WARNING: There is no error checking at all!

#!/bin/bash

ufile=$1 #user file name
ulf=$2 #user line from
ult=$3 #user line to

ifile=$4 #item file name
ilf=$5 #item line from
ilt=$6 #item line to

for user in `awk -vULF=$ulf -vULT=$ult 'NR>=ULF && NR<=ULT' $ufile` ; do
 for item in `awk -vILF=$ilf -vILT=$ilt 'NR>=ILF && NR<=ILT' $ifile` ; do
  echo $user @ $item
 done
done

Demonstration:

$ for i in {1..100}; do echo user$i >>userlist; done
$ for i in {1..100}; do echo item$i >>itemlist; done
$
$ ./script.sh userlist 23 30 itemlist 60 65
user23 @ item60
user23 @ item61
user23 @ item62
user23 @ item63
user23 @ item64
user23 @ item65
user24 @ item60
user24 @ item61
user24 @ item62
user24 @ item63
user24 @ item64
user24 @ item65
user25 @ item60
user25 @ item61
user25 @ item62
user25 @ item63
user25 @ item64
user25 @ item65
user26 @ item60
user26 @ item61
user26 @ item62
user26 @ item63
user26 @ item64
user26 @ item65
user27 @ item60
user27 @ item61
user27 @ item62
user27 @ item63
user27 @ item64
user27 @ item65
user28 @ item60
user28 @ item61
user28 @ item62
user28 @ item63
user28 @ item64
user28 @ item65
user29 @ item60
user29 @ item61
user29 @ item62
user29 @ item63
user29 @ item64
user29 @ item65
user30 @ item60
user30 @ item61
user30 @ item62
user30 @ item63
user30 @ item64
user30 @ item65
$ 

Thanks junior-helper for the help.

Sorry i was struck with imp release.

Now am back.

I tried what you said but it doesn't do anything, script just run and comeback.

admin@HP1 # cat script.sh
#!/usr/bin/bash

ufile=$1 #user file name
#ulf=$2 #user line from
ulf=25 #user line from
ult=30 #user line to

ifile=$4 #item file name
ilf=$5 #item line from
ilt=$6 #item line to

for user in `awk -vULF=$ulf -vULT=$ult 'NR>=ULF && NR<=ULT' $ufile` ; do
 for item in `awk -vILF=$ilf -vILT=$ilt 'NR>=ILF && NR<=ILT' $ifile` ; do
  echo $user @ $item
 done
done

I have both itemlsit and userlist file with 100 lines data in each

admin@HP1 # wc -l userlist itemlist
100 userlist
100 itemlist
200 total

Am i missing something here ?

My OS is :
uname -a
SunOS HP1 5.10 Generic_144489-09 i86pc i386 i86pc

Please let me know