Assigning value to a paramter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assigning value to a paramter
# 1  
Old 09-09-2011
Assigning value to a paramter

Howdy folks,
Im trying to assign the output of awk to a parameter.But it is not working.Need your input guys.


while read line
do
WInstname = `awk -F"Iname -" '{print $2}'`
done < input.txt

input.txt
Iname - 123
# 2  
Old 09-09-2011
Hi,

There are several errors in your script. Try something like this:
Code:
$ cat script.sh
#!/usr/bin/env bash

while read line
do
        WInstname=`echo $line | awk -F"Iname -" '{print $2}'`
done < input.txt
echo "$WInstname"
$ bash script.sh
 123

Regards,
Birei
# 3  
Old 09-09-2011
Thnks bro..We did exactly like you said however we are getting a blank output

[user@machine]# cat test
#!/usr/bin/ bash
while read line
do
WInstname=`echo $line | awk -F "Iname -" '{print $2}'`
done < input.txt
echo $WInstname





#WInstname = awk -F"Instancename -" '{print $2}'
[user@machine]# cat input.txt
Iname - 123

[user@machine]# ./test

[user@machine]#
# 4  
Old 09-09-2011
Looks like there is a space in your shebang statement between bin/ and bash. i.e. first line
#!/usr/bin/ bash

Remove the space and try.

Code:
awk -F"-" '{print $2}' iput.txt

--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Assigning ip to Solaris

Hi I cannot assign static ip address to my solaris machine. When i do dladm show-dev it shows nothing. (3 Replies)
Discussion started by: anfieldre
3 Replies

2. Shell Programming and Scripting

Assigning a variable

I have a date column as 06302015 but I need to have variable which extracts 063015. Am trying something like below but it is not assigning Please let me know if am missing something. Thanks in advance. ################################ #!/usr/bin/ksh DT=06302015 ... (7 Replies)
Discussion started by: weknowd
7 Replies

3. Shell Programming and Scripting

Assigning variables

i have variables RECIPIENTS_DEVL,RECIPIENTS_UACC,RECIPIENTS_PROD i have a case statement to get the phase variable: case ${WMD_UPHASE1} in u) WMD_UPHASE4=UACC;; i) WMD_UPHASE4=DEVL;; p) WMD_UPHASE4=PROD;; d) WMD_UPHASE4=DEVL;; *) WMD_UPHASE4=DEVL;; esac I am unable to... (3 Replies)
Discussion started by: Arun Mishra
3 Replies

4. Shell Programming and Scripting

To pass the .sql file as a paramter to sqlplus through shell programming

Hi, Currently i have a .sql file 1.sql. I need to pass that as a parameter through a shell script to the sqlplus inside the same shell script. How I should I do.can anyone help me pls. I have an req where I need to send the .sql file and the place where the script has to create a .csv... (9 Replies)
Discussion started by: Hemamalini
9 Replies

5. HP-UX

Assigning IP's

hi all, i want to know where i can add and IP address so when i do a "w", i can see what IP is assigned to which tty? i know in tru64 you just added an entry to /etc/hosts. this does not seem to be the case with hpux. thanks (12 Replies)
Discussion started by: macgre_r
12 Replies

6. Shell Programming and Scripting

Assigning Value of variable

Hi In my shell script, I'm trying to find the line count of a file and assign it to a variable. LINE_COUNT=$(wc -l $FILE_NAME) But when i display LINE_COUNT, i'm getting the linecount concatenated with the file name. I want only the number. How can i get the line count alone ? Someone... (2 Replies)
Discussion started by: janemary.a
2 Replies

7. Shell Programming and Scripting

Assigning a value to variable

Another newbie to Unix scripting Q.. How do you assign a value resulting from a command, such as awk, to a variable. I am currently trying:- $awk '{print $1}' file1 > variable1 with no change to $variable1. The line: $awk '{print $1}' file1 does print the first line of the... (3 Replies)
Discussion started by: sirtrancealot
3 Replies

8. Shell Programming and Scripting

making sure a command line paramter is a number

i need to make sure that a command line paramter is with in a certin set of numbers and i dont know how todo it with out checking individual numbers. if test $1 -eq (need something here) then echo hi fi like if i put individual numbers in there it works fine but how do i do a range (3 Replies)
Discussion started by: rcunn87
3 Replies

9. Shell Programming and Scripting

Parsing input paramter in a script

Hi folks I am having a little trouble in parsing a variable read into a ksh script I have a bunch of variables passed into script test.ksh HOST SERVER JOB1 JOB2 JOB3 JOB4 JOB5 What I want to do is read all the $JOB variables ($JOB1, $JOB2, $JOB3) into a variable and then read that variable... (2 Replies)
Discussion started by: Anubhav
2 Replies

10. UNIX for Dummies Questions & Answers

Asking on taking in and out paramter

Hi , as i'm doing a .sh script that uses $datafile variable to spool my value into another .sh script. How do i spool out my maybe another value from my second script file back to my first .sh script??? What does this exit $? mean? Thanks a lot! (1 Reply)
Discussion started by: blueberry80
1 Replies
Login or Register to Ask a Question