How to pass arguments based on input file?

This script is running some exe file we are passing three argumnet below custome key word

Want to update script based on input files every time it will take argument from input file

below is the input files should take this input put it into the script.

k.ksh

cd /u/kali/temp


${APPS}/kali/bin/u_tra <<EOD
CUSTOM
18633
ABRTC
Auto mob

EOD


input.txt

18658
AQBCD
Squrt mob
18995
COTSYN
Cot sys

first it wil take 3

18658
AQBCD
Squrt mob 

then next 3

18995
COTSYN
Cot sys

try something like:

cd /u/kali/temp

lines=$(wc -l input.txt)
line=1

while [ $line -le ${lines% *} ]
do
   awk 'NR==l, NR==l+2' l=$line input.txt | ${APPS}/kali/bin/u_tra
   (( line = line + 3 ))
done

So - you want CUSTOM and three lines from that file plus an empty line presented on stdin to your script ${APPS}/kali/bin/u_tra . We are NOT talking of presenting the lines a command parameters?

Thanks for replay sorry for getting confusing
This is the main script

cd /u/kali/temp


${APPS}/kali/bin/u_tra <<EOD
CUSTOM
18633
ABRTC
Auto mob

EOD

Below code if we will do manually pass value as per input file now we have 2 times passing the parameter while runing the script
may be will pass more then 2 times

cd /u/kali/temp


${APPS}/kali/bin/u_tra <<EOD
CUSTOM
18658
AQBCD
Squrt mob


EOD

${APPS}/kali/bin/u_tra <<EOD
CUSTOM
18995
COTSYN
Cot sys

EOD

And run the scripts

I need to write a scripts which will pick values from input file.

you can consider

below input file format

18658
AQBCD
Squrt mob
18995
COTSYN
Cot sys

or

18658,AQBCD,Squrt mob
18995,COTSYN,Cot sys

Try

< input.txt split -l3 --filter="{ echo CUSTOM; cat $FILE; echo; } | ${APPS}/kali/bin/u_tra"

parameter should be pass under the EOD and missing the syntax and space also

${APPS}/kali/bin/u_tra <<EOD
CUSTOM
18658
AQBCD
Squrt mob


EOD

Is this a homework assignment? Does your instructor require that you use a here-document to complete this assignment?

If not, why do you care whether your input data (NOT parameters; parameters are command-line arguments) is read from a pipe or from a here-document?

I might guess that RudiC's code doesn't work for you because it only invokes your application once, but since you haven't clearly described how that application works, we are still guessing at what your real requirements are.

Is there any difference in the output produced by the commands:

cd /u/kali/temp


${APPS}/kali/bin/u_tra <<EOD
CUSTOM
18658
AQBCD
Squrt mob

EOD

${APPS}/kali/bin/u_tra <<EOD
CUSTOM
18995
COTSYN
Cot sys

EOD

and the commands:

cd /u/kali/temp


${APPS}/kali/bin/u_tra <<EOD
CUSTOM
18658
AQBCD
Squrt mob

CUSTOM
18995
COTSYN
Cot sys

EOD

?

Did you try the code RudiC suggested, or did you just decide that it won't work without trying it?

Note that in post #1 you said that there had to be one empty line before the "EOD". In post #4 you show two examples with one empty line and one example with two empty lines. And in post #6 you show one example with two empty lines. Which examples are correct???

What exactly does:

mean? Shell command line syntax must be followed when writing shell scripts. If you leave out the syntax, the script can't work? What "space also" do you want to leave out?

Please use complete sentences when posting here, with punctuation so we can understand what you're trying to say. Please use capitalization at the start of your sentences so we can understand what you're trying to say. Please help us help you by taking the time needed to clearly explain what you are trying to do and show us examples that support the description of the problem you're trying to solve.

Thanks Don sorry for haven't clearly mentioned my assignment
its require here-document to complete assignment if will pass arguments then its generate reports
if we pass 2 times or may be 3 times different arguments then it will generate 2 or 3 reports to execute 2 or 3 times exe file

So we are doing manually as i mentioned above in the code to avoid this i want to put input file all arguments and run exe file so that it will generate the report below is the main syntax we are using for generate one report

 cd /u/kali/temp
 
${APPS}/kali/bin/u_tra <<EOD
CUSTOM
 
EOD
 

below code if we generate 2 or 3 report then we have to copy same thing 2 or 3 times with different arguments below custom keyword
while copy pest doing mistake please ignore my last comments

${APPS}/kali/bin/u_tra <<EOD
CUSTOM
18658
AQBCD
Squrt mob
  
EOD
${APPS}/kali/bin/u_tra <<EOD
CUSTOM
18995
COTSYN
Cot sys
  
EOD
${APPS}/kali/bin/u_tra <<EOD
CUSTOM
18789
COSTER
ctc resr
  
EOD
 

if will copy all arguments and keep in input file while script run then it will take the data from input file and generate
the reports to avoid manual process below is the input file format

18658
AQBCD
Squrt mob
18995
COTSYN
Cot sys
18789
COSTER
ctc resr
 

or

18658,AQBCD,Squrt mob
18995,COTSYN,Cot sys
18789,COSTER,ctc resr

I have not mentioed the shell command because of have mentioned small part of my scripts

Moderator comments were removed during original forum migration.
1 Like