# How to pass arguments based on input file?

**URL:** <https://community.unix.com/t/how-to-pass-arguments-based-on-input-file/370437>\
**Category:** Shell Programming and Scripting\
**Created:** [January 18, 2018, 5:22am UTC](https://community.unix.com/t/how-to-pass-arguments-based-on-input-file/370437 "2018-01-18T05:22:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kalia](https://community.unix.com/letter_avatar/kalia/32/6_449c533f586939b6e5f246632a46421f.png) [@Kalia](https://community.unix.com/u/Kalia)\
**Post date:** [January 18, 2018, 5:22am UTC](https://community.unix.com/t/how-to-pass-arguments-based-on-input-file/370437/1 "2018-01-18T05:22:53Z")

</div>

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

```nohighlight
cd /u/kali/temp

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

EOD

```

input.txt

```nohighlight
18658
AQBCD
Squrt mob
18995
COTSYN
Cot sys

```

first it wil take 3

```nohighlight
18658
AQBCD
Squrt mob 

```

then next 3

```nohighlight
18995
COTSYN
Cot sys

```

---

<div class="post-metadata">

**Author:** ![rdrtx1](https://community.unix.com/user_avatar/community.unix.com/rdrtx1/32/2721_2.png) [@rdrtx1](https://community.unix.com/u/rdrtx1)\
**Post date:** [January 18, 2018, 11:19am UTC](https://community.unix.com/t/how-to-pass-arguments-based-on-input-file/370437/2 "2018-01-18T11:19:09Z")

</div>

try something like:

```nohighlight
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

```

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [January 18, 2018, 12:35pm UTC](https://community.unix.com/t/how-to-pass-arguments-based-on-input-file/370437/3 "2018-01-18T12:35:08Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Kalia](https://community.unix.com/letter_avatar/kalia/32/6_449c533f586939b6e5f246632a46421f.png) [@Kalia](https://community.unix.com/u/Kalia)\
**Post date:** [January 19, 2018, 6:29am UTC](https://community.unix.com/t/how-to-pass-arguments-based-on-input-file/370437/4 "2018-01-19T06:29:14Z")

</div>

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

```nohighlight
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

```nohighlight
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

```nohighlight
18658
AQBCD
Squrt mob
18995
COTSYN
Cot sys

```

or

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

```

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [January 19, 2018, 6:32am UTC](https://community.unix.com/t/how-to-pass-arguments-based-on-input-file/370437/5 "2018-01-19T06:32:24Z")

</div>

Try

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

```

---

<div class="post-metadata">

**Author:** ![Kalia](https://community.unix.com/letter_avatar/kalia/32/6_449c533f586939b6e5f246632a46421f.png) [@Kalia](https://community.unix.com/u/Kalia)\
**Post date:** [January 19, 2018, 7:10am UTC](https://community.unix.com/t/how-to-pass-arguments-based-on-input-file/370437/6 "2018-01-19T07:10:50Z")

</div>

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

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

EOD

```

---

<div class="post-metadata">

**Author:** ![Don\_Cragun](https://community.unix.com/user_avatar/community.unix.com/don_cragun/32/2682_2.png) [@Don\_Cragun](https://community.unix.com/u/Don_Cragun)\
**Post date:** [January 20, 2018, 12:05am UTC](https://community.unix.com/t/how-to-pass-arguments-based-on-input-file/370437/7 "2018-01-20T00:05:34Z")

</div>

> [@kalia](#):
>
> parameter should be pass under the EOD and missing the syntax and space also
> 
> ```plaintext
> ${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:

```plaintext
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:

```plaintext
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:

> [@](#):
>
> parameter should be pass under the EOD and missing the syntax and space also

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.

---

<div class="post-metadata">

**Author:** ![Kalia](https://community.unix.com/letter_avatar/kalia/32/6_449c533f586939b6e5f246632a46421f.png) [@Kalia](https://community.unix.com/u/Kalia)\
**Post date:** [January 20, 2018, 9:34am UTC](https://community.unix.com/t/how-to-pass-arguments-based-on-input-file/370437/8 "2018-01-20T09:34:29Z")

</div>

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

```nohighlight
 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

```nohighlight
${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

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

```

or

```nohighlight
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

---

<div class="post-metadata">

**Author:** ![Don\_Cragun](https://community.unix.com/user_avatar/community.unix.com/don_cragun/32/2682_2.png) [@Don\_Cragun](https://community.unix.com/u/Don_Cragun)\
**Post date:** [January 20, 2018, 9:44am UTC](https://community.unix.com/t/how-to-pass-arguments-based-on-input-file/370437/9 "2018-01-20T09:44:02Z")

</div>

Moderator comments were removed during original forum migration.
