How to pass arguments based on input file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pass arguments based on input file?
# 1  
Old 01-18-2018
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
Code:
cd /u/kali/temp


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

EOD

input.txt

Code:
18658
AQBCD
Squrt mob
18995
COTSYN
Cot sys

first it wil take 3
Code:
18658
AQBCD
Squrt mob

then next 3
Code:
18995
COTSYN
Cot sys

Moderator's Comments:
Mod Comment Please use CODE tags for data as well as required by forum rules!

Last edited by RudiC; 01-18-2018 at 07:06 AM.. Reason: Added CODE tags.
# 2  
Old 01-18-2018
try something like:
Code:
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

# 3  
Old 01-18-2018
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?
# 4  
Old 01-19-2018
Thanks for replay sorry for getting confusing
This is the main script
Code:
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

Code:
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
Code:
18658
AQBCD
Squrt mob
18995
COTSYN
Cot sys

or
Code:
18658,AQBCD,Squrt mob
18995,COTSYN,Cot sys

# 5  
Old 01-19-2018
Try
Code:
< input.txt split -l3 --filter="{ echo CUSTOM; cat $FILE; echo; } | ${APPS}/kali/bin/u_tra"

# 6  
Old 01-19-2018
parameter should be pass under the EOD and missing the syntax and space also

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


EOD

Moderator's Comments:
Mod Comment Please use code tags (as required by forum rules) whenever posting sample input, output, and code segments.

Last edited by Don Cragun; 01-19-2018 at 09:34 PM.. Reason: Add CODE tags again.
# 7  
Old 01-20-2018
Quote:
Originally Posted by Kalia
parameter should be pass under the EOD and missing the syntax and space also

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


EOD

Moderator's Comments:
Mod Comment Please use code tags (as required by forum rules) whenever posting sample input, output, and code segments.
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:
Code:
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:
Code:
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:
Quote:
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read file lines and pass line values as arguments.

Dears, Need help to implement below requirement A file (detail.txt)contain : 1st column: Stream 2nd column: PathAddress 3rd column: Counterlimit 4th column: TransactionDateColumn 5th column: DateType 6th column: SleepValue 7th column: Status Need to write a... (1 Reply)
Discussion started by: sadique.manzar
1 Replies

2. Shell Programming and Scripting

How pass the input parameter to a file in the script ?

OS version: RHEL 6.7 myTextFile.txt file is referred within Script1.sh script, I only execute Script1.sh and I want the input variable to be passed inside myTextFile.txt . Any idea how I can do this ? $ cat script1.sh cat myTextFile.txt $ cat myTextFile.txt $1 Requirement1.... (4 Replies)
Discussion started by: kraljic
4 Replies

3. Shell Programming and Scripting

Read input from file and pass it to sub shell

i have a scenario where in i have to monitor jobs which run in different servers, The job details(job name, host server, etc) are present in a dat file. I have written a script a script which reads the details from the dat file and calls a local method where the job monitoring logic is present.... (2 Replies)
Discussion started by: abubucker0
2 Replies

4. UNIX for Dummies Questions & Answers

To pass multiple arguments from file in to an sql query

Hi all , I want to pass contents from a file say f1 as arguments to a sql query which has In statement using a script example select * from table_1 where login in ( `cat f1`) ; will this work or is there any other way to do it. (1 Reply)
Discussion started by: zozoo
1 Replies

5. UNIX for Dummies Questions & Answers

Pass arguments to the library .so

Hello, Please, how can i pass arguments to my lib.so ? my lib.so is written in c and i need some arguments in the code .. LD_PRELOAD=lib.so ./program Thank you. (1 Reply)
Discussion started by: chercheur857
1 Replies

6. Shell Programming and Scripting

pass arguments unchanged

Hi, I have to use ksh on HP-UX for some scripting. I usually use "set -e -u" in scripts to stop if errors occur or a typo is in a variable name. Now I try to use "$@" to pass the arguments unchanged to another function, which works without problems - unless I try to call the script without... (7 Replies)
Discussion started by: michas
7 Replies

7. Shell Programming and Scripting

How to pass arguments to SQL file passed in shell script?

Hi, I am using SYBASE database. in my script i am connecting to DB via using isql. isql -U${S_USER} -S${S_SERV} -D${S_DB} -P${S_PWD} -b0 -w3000 -h0 -s"|" -i${MYDIR}/ABC.sql -oXYZ.txt << FINSQL i am taking a ABC.sql file to use the queries written in it and storing the output in... (3 Replies)
Discussion started by: dazdseg
3 Replies

8. Shell Programming and Scripting

Pass input and output file as parameter to awk script

Hi, i am new to awk. I am using csv2pipe script(shown below) BEGIN { FS=SUBSEP; OFS="|" } { result = setcsv($0, ",") print } # setcsv(str, sep) - parse CSV (MS specification) input # str, the string to be parsed. (Most likely $0.) # sep, the separator between the values. # #... (6 Replies)
Discussion started by: bhaskarjha178
6 Replies

9. UNIX for Advanced & Expert Users

Pass Kill with arguments

Dude, I want to kill a process, but the processid is in a text file. I have to read the text file for the process id and pass it as parameter to the kill command. Example $ cat prcid.txt 18650 I want to pass the value 18650 as a process id to kill command. $ kill -9 <value read from... (4 Replies)
Discussion started by: aksmuralee
4 Replies

10. Shell Programming and Scripting

read a file as input and pass each line to another script

Hi, I am trying to write a ftp script which will read a file for filenames and ftp those files to another server. Here's my ftp script, but it's scanning the current directory for file names. My question is how can I pass multiple files (these files will have the name of data files that need to... (0 Replies)
Discussion started by: sajjad02
0 Replies
Login or Register to Ask a Question