How to call multiple variables in bash !!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to call multiple variables in bash !!
# 1  
Old 03-18-2011
How to call multiple variables in bash !!

Hi all ,

I have a file with below data ,
Code:
bash#cat file.txt 
user1  amount1  status1
user2  amount2  status2
user3  amount3  status3
user4  amount4  status4
.
.
.

Now i have a command to be executed with above values like below ,
Code:
  ./errorcheck -u user1 -a amount1 -s status1
  ./errorcheck -u user2 -a amount2 -s status2
  ./errorcheck -u user3 -a amount3 -s status3

How to put these variables on this command so with one command i can execute all the checks ?

Thanks

Last edited by Franklin52; 03-18-2011 at 05:51 AM.. Reason: Please use code tags
# 2  
Old 03-18-2011
Code:
awk '{printf "./errorcheck -u %s -a %s -s %s\n",$1,$2,$3}' file.txt |sh

# 3  
Old 03-18-2011
Code:
while read user amount status; do
  ./errorcheck -u "$user" -a "$amount" -s "$status"
done < file.txt

# 4  
Old 03-18-2011
Hi gnanasekar_beem,

Another similar way:
Code:
awk '{print "./errorcheck -u",$1,"-a",$2,"-s",$3}' file.txt > . commands_to_send.sh
. commands_to_send.sh

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to call exeute multiple bash shells from one master shell?

I have few bash shells, which i want to run sequentially, how to create a shell file, and execute/call one after other shell file. I am very new to shell programming. Bult some and running individually and also with crontab scheduler. never had a shell calling other shells, kindly would like... (2 Replies)
Discussion started by: cplusplus1
2 Replies

2. Shell Programming and Scripting

Assigning multiple column's value from Oracle query to multiple variables in UNIX

Hi All, I need to read values of 10 columns from oracle query and assign the same to 10 unix variables. The query will return only one record(row). I tried to append all these columns using a delimiter(;) in the select query and assign the same to a single variable(V) in unix. I thought I... (3 Replies)
Discussion started by: hkrishnan91
3 Replies

3. Shell Programming and Scripting

Multiple bash variables passed into nawk

I have a file that has 2 fields called b_file: 11977 DAR.V3.20150209.1.CSV 3295 DAR.V3.20150209.1.CSV 1721 DAR.V2.20150210.1.CSV I need to search a sftplog using the field 1, but want to maintain the relationship between field 1 and 2. I am passing field 1 as a parameter in a bash loop. ... (14 Replies)
Discussion started by: smenago
14 Replies

4. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

5. Shell Programming and Scripting

Need Help: Shell script to call sql session with variables stored in .txt file

Hi, I need help in writing a shell script which can read data from a text file (Cancel_ID.txt) and then calls sqlplus session (Cancel.sql) with the first line parameter of the text file ("0322600453") till all rows are not completed. ... (4 Replies)
Discussion started by: Khan28
4 Replies

6. Shell Programming and Scripting

Reading multiple values from multiple lines and columns and setting them to unique variables.

Hello, I would like to ask for help with csh script. An example of an input in .txt file is below, the number of lines varies from file to file and I have 2 or 3 columns with values. I would like to read all the values (probably one by one) and set them to independent unique variables that... (7 Replies)
Discussion started by: FMMOLA
7 Replies

7. Shell Programming and Scripting

BASH arrays and variables of variables in C++

Sometimes it is handy to protect long scripts in C++. The following syntax works fine for simple commands: #define SHELLSCRIPT1 "\ #/bin/bash \n\ echo \"hello\" \n\ " int main () { cout <<system(SHELLSCRIPT1); return 0; } Unfortunately for there are problems for: 1d arrays:... (10 Replies)
Discussion started by: frad
10 Replies

8. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

9. Shell Programming and Scripting

Multiple Variables for BASH script

Hello, I am new to the whole "scripting" thing. Below is the script that I have so far and where i need the Variables to go (VAR#) #!/bin/bash #Sample Script VAR1= echo "Choose an option: 1) Create a file. 2) Delete a file. 3) Move a file." read VAR1 case $VAR1 in 1) echo "Pick... (4 Replies)
Discussion started by: eclerget
4 Replies

10. Shell Programming and Scripting

how to assign a value to several variables inside awk call

Hi I am using 'awk" to get file size and date of the file: op - sundev3 $ ls -l /bb/bin/tsfiles.sel | awk '{print $5 $6 $7}' 1587May8 May be somobody knows the way to combine this command with variable assignmet inside the awk, so I would have variables SIZE, MONTH and DATE assigned after... (1 Reply)
Discussion started by: aoussenko
1 Replies
Login or Register to Ask a Question