How to take input from different files for using the counter variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to take input from different files for using the counter variable?
# 1  
Old 05-31-2013
How to take input from different files for using the counter variable?

Hi All,

I have script which call test utility and it takes token input which is kept in a separate file. now instead of taking tokens from single file,will keep 5 input files and script should read tokens from each files.

EX : There will 5 token.txt file which will have say around 1000 (token)lines, once it has read first 1000 token from first file, it should switch over to next file ans so on..

Any help please..

root@aat # cat loader.sh

Code:
num=1
MAX_SLAVE=500
TOKEN_COUNT=10


while [ $num -lt $MAX_SLAVE ] ; do date "+%Y%m%d %H:%M:%S : client $num started"
./loader -u ../token.txt -i itemlist -c $TOKEN_COUNT -s IT  >> /tmp/loader.log &
(( num++ ))
done
date "+%Y%m%d %H:%M:%S : client $MAX_SLAVE started"
./loader -u ../token.txt -i itemlist -c $TOKEN_COUNT -s IT |tee -a /tmp/loader.log
date "+%Y%m%d %H:%M:%S : client $MAX_SLAVE completed"

# 2  
Old 05-31-2013
Quote:
Originally Posted by Optimus81
EX : There will 5 token.txt file which will have say around 1000 (token)lines, once it has read first 1000 token from first file, it should switch over to next file ans so on.
Code:
filearr=( tokfile1.txt
          tokfile2.txt
          tokfile3.txt
          tokfile4.txt
          tokfile5.txt
        )

for file in ${filearr[@]}
do
    while read token
    do
        ...
        ...
        <do more with $token>
        ...
        ...
    done < $file
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Counter based on 10 files or less

there are around 676 files in a directory and I want to batch every 10 and then remaining 7 files as well for a batch pressing job simultaneously. I'm trying to pick-up every 10 counter'd files -- batch these files and then move on with the next batch.. after resetting the Counters back to 0; ... (5 Replies)
Discussion started by: busyboy
5 Replies

2. UNIX for Advanced & Expert Users

Passing variable as input & storing output in other variable

I have a below syntax its working fine... var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Discussion started by: sam@sam
5 Replies

3. Shell Programming and Scripting

Naming output files based on variable parameters and input filenames

Hello, I have a series of files in sub-directories that I want to loop through, process and name according to the input filename and the various parameters I'm using to process the files. I have a number of each, for example file names like AG005574, AG004788, AG003854 and parameter values like... (2 Replies)
Discussion started by: bdeads
2 Replies

4. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

5. Shell Programming and Scripting

XML variable for input in same input file

Dear All , i stuck in one problem executing xml .. i have input xml as <COMMAND name="ARRANGEMENT.WRITE" timestamp="0" so="initial"> <SVLOBJECT> <LONG name="CSP_PMNT_ID" val="-1"/> <MONEY name="CSP_CEILING" amount="0.0" currency="AUD"/> ... (6 Replies)
Discussion started by: arvindng
6 Replies

6. Shell Programming and Scripting

grouping log files based on counter

I have my log file as below 00:18:02 - Nothing normal; Garbage Collection kicked off & running from last 3 min... 00:19:02 - Nothing normal; Garbage Collection kicked off & running from last 4 min... 00:19:02 - Nothing normal; Garbage Collection kicked off & running from last 4 min...... (11 Replies)
Discussion started by: manas_ranjan
11 Replies

7. Shell Programming and Scripting

adding counter to a variable while moving in a loop

The scenario is like this : I need to read records from a file one by one and increment counter1, if a certain field matches with a number say "40"..the script should increment the counter2 and also extract a corresponding field from the same line and adding them one by one and redirecting the the... (5 Replies)
Discussion started by: mady135
5 Replies

8. Shell Programming and Scripting

variable number of input files

Hi all, I'm an extremely newbie with unix/perl. I have a perl script that I need to run on a variable number of input files (i.e., I have to run the perl script on each file, but from run to run, I have a different list of files that need to be put through this script). I think this can... (2 Replies)
Discussion started by: sunmatrix
2 Replies

9. Shell Programming and Scripting

counter in a variable - can it be done?

I have the following for(( i=1; 1<=2; i++)) do e1=123 n1=123 e2=456 n2=456 coord= $e1,$n1 echo "coordinate=$coord" done exit this echos coordinate=123,123 I need it to loop so: loop1 coord=$e1,$n1 loop2 (3 Replies)
Discussion started by: gazz1982
3 Replies

10. Shell Programming and Scripting

Loop counter variable display

Hello everyone, how can I send output to the screen from a running script or tcl, in such a way that if a loop is executing I will see the rolling counter on my screen as the records are processed in the loop. I do not want the screen to scroll, though. In other words can a var's value be painted... (2 Replies)
Discussion started by: lifespan
2 Replies
Login or Register to Ask a Question