Sponsored Content
Full Discussion: How to parse nested variable
Top Forums UNIX for Advanced & Expert Users How to parse nested variable Post 302508803 by apskaushik on Tuesday 29th of March 2011 05:41:59 AM
Old 03-29-2011
How to parse nested variable

Hi,

I want to parse nested variable in my script.
for exp-
c=1
G1='0318'
G2='0023'
G3='3092'
G4='0014'

while [ $c -le 4 ];do
g=G$c
a=$g
echo "Group=$g and value=$a"
c=`expr $c + 1`
done

final output are as -
---------------------------
Group=G1 and value=G1
Group=G2 and value=G2
Group=G3 and value=G3
Group=G4 and value=G4

while i need output as -
----------------------------
Group=G1 and value=0318
Group=G2 and value=0023
Group=G3 and value=3092
Group=G4 and value=0014

any help is appreciated.

Thanks
Amit
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

parse variable

I have a variable (it is a date actually -> 2007-01-03) which would be passed in as parameter, what I want is to parse in and put year, month, and day in separate variables, I have tried the following but doesn't work echo $dt | awk -F- '{print $1 $2 $3}' | read y m d Thanks in... (2 Replies)
Discussion started by: mpang_
2 Replies

2. Shell Programming and Scripting

Variable in While Loop Nested If

Hi all, I'm having problems with the setting a variable in a nested if statement. It doesn't seem to change even if it mets the 'if' condition. My script essentially looks for a user name from the output from a kerberos command. When I find the user name, I tried to change a variable and exit... (6 Replies)
Discussion started by: geass
6 Replies

3. Shell Programming and Scripting

how to parse value of the variable

I have a variable which has a full path to the file, for example : A=/t1/bin/f410pdb Does anybody know the command to parce this variable and assign the result to 3 other variables so each subdirectory name will be in a new variable like this B=t1 C=bin D=f410pdb Many thanks -A (5 Replies)
Discussion started by: aoussenko
5 Replies

4. Shell Programming and Scripting

Enviornment Variable in B shell (I call it nested variable)

#!/bin/sh APP_ROOT_MODE1=/opt/app1.0 APP_ROOT_MODE2=/opt/app2.0 APP_ROOT=${APP_ROOT_${APP_MODE}} # enviornment variable APP_MODE will be exported in the terminal where # we run the applciation, its value is string - MODE1 or MODE2 # My intension is: # when export APP_MODE=MODE1... (4 Replies)
Discussion started by: princelinux
4 Replies

5. Shell Programming and Scripting

nested double quota and white space inside variable

I have a question about nested double quotes. Any help is appreciated. Here are my commands on Mac OS. # string="Ethernet \"USB Ethernet\" \"Bluetooth DUN\" AirPort FireWire \"Bluetooth PAN\"" # echo $string Ethernet "USB Ethernet" "Bluetooth DUN" AirPort FireWire "Bluetooth PAN" #... (3 Replies)
Discussion started by: lindazhou
3 Replies

6. Shell Programming and Scripting

big xml file with nested loop parse

I have an xml file with the structure: <tag1> <value1>xyx</value1> <value2>123</value2> </tag1> <tag1> <value1>568</value1> <value2>zzzzz</value2> </tag1> where I want to parse each data pair in the this single file, so something like: find first tag1 data pair... (1 Reply)
Discussion started by: unclecameron
1 Replies

7. Shell Programming and Scripting

Using shell command need to parse multiple nested tag value of a XML file

I have this XML file - <gp> <mms>1110012</mms> <tg>988</tg> <mm>LongTime</mm> <lv> <lkid>StartEle=ONE, Desti = Motion</lkid> <kk>12</kk> </lv> <lv> <lkid>StartEle=ONE, Source = Velocity</lkid> <kk>2</kk> </lv> <lv> ... (3 Replies)
Discussion started by: NeedASolution
3 Replies

8. Shell Programming and Scripting

Nested variable allocation

I've made a number of errors with this and am trying to work a solution within the same framework. /bin/ksh for host_name in ahost1 ahost2 bhost1 bhost2 do for host_prefix in a b do if echo ${host_name} | grep -qi ${host_prefix} then if ... (1 Reply)
Discussion started by: squrcles
1 Replies

9. Shell Programming and Scripting

How to add second variable in awk nested if condition?

Hi Gurus, I have a command to assign value based on input value. current condition is "if pattern matches "case", then assign "HOLD" else "SUCC"right now, I need to add one more condition (variable name is VAR). the condition is "if pattern1 matches "case", then assign "HOLD" else if... (2 Replies)
Discussion started by: ken6503
2 Replies

10. UNIX for Beginners Questions & Answers

Grepping for one variable while using awk to parse an associated variable

Im trying to search for a single variable in the first field and from that output use awk to extract out the lines that contain a value less than a value stored in another variable. Both the variables are associated with each other. Any guidance is appreciated. File that contains the... (6 Replies)
Discussion started by: ncwxpanther
6 Replies
NUMFMT_PARSE(3) 							 1							   NUMFMT_PARSE(3)

NumberFormatter::parse - Parse a number

	Object oriented style

SYNOPSIS
public mixed NumberFormatter::parse (string $value, [int $type], [int &$position]) DESCRIPTION
Procedural style mixed numfmt_parse (NumberFormatter $fmt, string $value, [int $type], [int &$position]) Parse a string into a number using the current formatter rules. PARAMETERS
o $fmt -NumberFormatter object. o $type - The formatting type to use. By default, NumberFormatter::TYPE_DOUBLE is used. o $position - Offset in the string at which to begin parsing. On return, this value will hold the offset at which parsing ended. RETURN VALUES
The value of the parsed number or FALSE on error. EXAMPLES
Example #1 numfmt_parse(3) example <?php $fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL ); $num = "1.234.567,891"; echo numfmt_parse($fmt, $num)." "; echo numfmt_parse($fmt, $num, NumberFormatter::TYPE_INT32)." "; ?> Example #2 OO example <?php $fmt = new NumberFormatter( 'de_DE', NumberFormatter::DECIMAL ); $num = "1.234.567,891"; echo $fmt->parse($num)." "; echo $fmt->parse($num, NumberFormatter::TYPE_INT32)." "; ?> The above example will output: 1234567.891 1234567 SEE ALSO
numfmt_get_error_code(3), numfmt_format(3), numfmt_parse_currency(3). PHP Documentation Group NUMFMT_PARSE(3)
All times are GMT -4. The time now is 12:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy