Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Assigning evaluated expression to a variable Post 302217089 by Vi-Curious on Tuesday 22nd of July 2008 12:55:30 AM
Old 07-22-2008
Code:
 
#!/usr/bin/bash
i=test.txt
j=B10
var1=SERVER_"$j"
echo "DBSERVER = $var1"
eval var1=`grep "^DBSERVER=" "$i" | cut -d"=" -f2`
echo "DBSERVER = $var1"

With file test.txt containing:
Code:
 
line 1
 DBSERVER=SERVER_XXX
line 3
DBSERVER=SERVER_A1
line 5

Produces the following when run:
Code:
 
HOSTNAME:> test.sh
DBSERVER = SERVER_B10
DBSERVER = SERVER_A1

 

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

assigning a variable

hi all, in ksh, how do i assign the output of a find command to a variable, e.g am trying something like this : totalNoFiles=$(print find ./ -name "SystemOut*.log"); but when i echo $totalNoFiles it displays find ./ -name "SystemOut*.log" instead of the total number of... (2 Replies)
Discussion started by: cesarNZ
2 Replies

3. Shell Programming and Scripting

Assigning value to a variable

Is there any difference between: set variable=39 and variable=39 (1 Reply)
Discussion started by: proactiveaditya
1 Replies

4. Shell Programming and Scripting

Removing a character from a variable and assigning it to another variable?

Hi folks. I have this variable called FirstIN that contains something like this: 001,002,003,004... I am trying to assign the content of this variable into ModifiedIN but with the following format : 001 002 003 004...(changing the commas for spaces) I thought about using sed but i am not... (17 Replies)
Discussion started by: Stephan
17 Replies

5. Shell Programming and Scripting

Variable is not evaluated in awk statement

Dear All, I have one problem in my script, awk statement as 1. it is not evaluate the second variable $stake but the first one $channel is being done. 2.I want to assign the whole awk statement to a variable actual_code which is not being executed in my script. #!/usr/bin/sh echo "Enter... (3 Replies)
Discussion started by: chinmayadalai
3 Replies

6. Shell Programming and Scripting

Assigning expression value to tcsh variables

Hi All, I have a tcsh script as: #!/usr/bin/csh -x set packsName=$(awk -F'' '/^execute.*=true/{print $2}' ExecutePacks.config) for var in $packsName do echo "printed $var" done I want to assign the value which is returned by awk function to the variable called packsName. How do I... (2 Replies)
Discussion started by: AB10
2 Replies

7. Shell Programming and Scripting

problem in assigning value to variable have value fo other variable

my script is some thing like this i11="{1,2,3,4,5,6,7,8,9,10,11,}" echo "enter value" read value ..............suppose i11 x="$value" echo "$($value)" .............the echo should be {1,2,3,4,5,6,7,8,9,10,11,} but its showing "i11" only. plz help me out to get desired... (10 Replies)
Discussion started by: sagar_1986
10 Replies

8. Shell Programming and Scripting

assigning value of a expression to a variable

eval echo \$tts_space_name$count i m getting output of this stmnt as 'TBS_ADOX_EXTR3' but, I m not able to assign this value to a variable . i tried export j=`eval echo \$tts_space_name$count` eval j= `eval echo \$tts_space_name$count` and when i do echo $j ... i get o/p as 1 or 2... (1 Reply)
Discussion started by: Gl@)!aTor
1 Replies

9. Shell Programming and Scripting

Assigning a value to a variable

Hi I have a script that accepts an input date in YYYY-MM-DD format. After that, I used sed to delete the hyphen (-) which gives me an output YYYY MM DD. My question is, how can I assign those three numbers to a three different variable. Example: 2013-11-23 will become 2013 11 23... (4 Replies)
Discussion started by: erin00
4 Replies

10. Solaris

Assigning an expression to a variable in shell script

i am trying to assign the following expression to a variable in Unix shell script and want to use that variable in some other expression. But unable to get the required thing done. Please help with this.... This is the expression which i want to provide as input the variable date '+%y:%m:%d' |... (3 Replies)
Discussion started by: ssk250
3 Replies
ZGREP(1)						      General Commands Manual							  ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 09:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy