Sponsored Content
Top Forums Shell Programming and Scripting Problem with awk array when loading from shell variable Post 302822605 by cskumar on Tuesday 18th of June 2013 02:07:19 AM
Old 06-18-2013
Problem with awk array when loading from shell variable

Hi, I have a problem with awk array when iam trying to use awk in solaris box as below..Iam unable to figure out the problem..
Need your help. is there any alternative to make it in arrays from variable values

Code:
nawk 'BEGIN {SUBSEP=" ";
split("101880|110045 101887|110045 101896|110045 101903|110045 101910|110045 101919|110045 101926|110045 101933|110045 101941|110045 101948|110045 101957|110046 101966|110045 101975|110046 101992|110045 102002|110046 102009|110046 102016|110046 102024|110046 102033|110046 102048|110046 102063|110046 102078|110046 102093|110047 102103|110046 102112|110047 102128|110047 102137|110047 102144|110047 102151|110047 102160|110047 102168|110047",Val," ");
} 
END {
for (i in Val) print i,Val[i]
}
' $FILE

O/p--Success

Code:
nawk 'BEGIN {SUBSEP=" ";
split('${LINENUMBER_JOBID}',Val," ");
} 
END {
for (i in Val) print i,Val[i]
}
' $FILE

O/p Error:---
nawk: syntax error at source line 2
 context is
         >>> split(101880|110045 <<<
nawk: illegal statement at source line 2
        missing }
        missing )

Shell variable value:
-------------------
Code:
 echo "--${LINENUMBER_JOBID}==="--101880|110045
101887|110045
101896|110045
101903|110045
101910|110045
101919|110045
101926|110045
101933|110045
101941|110045
101948|110045
101957|110046
101966|110045
101975|110046
101992|110045
102002|110046
102009|110046
102016|110046
102024|110046
102033|110046
102048|110046
102063|110046
102078|110046
102093|110047
102103|110046
102112|110047
102128|110047
102137|110047
102144|110047
102151|110047
102160|110047
102168|110047===


Last edited by zaxxon; 06-18-2013 at 10:04 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK program with array variable

Hi, I made a small awk program just to test array variables. I couldn't find anything wrong with it. But it doesn't give out valid numbers.( just 0.00 ) Do you see any problem that I didn't see? Thanks in advance! Here is the program: ################################## BEGIN { FS =... (4 Replies)
Discussion started by: whatisthis
4 Replies

2. Shell Programming and Scripting

Function loading in a shell scripting like class loading in java

Like class loader in java, can we make a function loader in shell script, for this can someone throw some light on how internally bash runs a shell script , what happenes in runtime ... thanks in advance.. (1 Reply)
Discussion started by: mpsc_sela
1 Replies

3. Shell Programming and Scripting

Parameter Problem With an Array Variable

Hi, I have two bash shell scripts: test: rrdhcp78-120:test_data msb65$ cat ~/bin/test #!/bin/sh array1=() echo 'elements in array1:' ${#array1} ~/bin/test2 $array1 test2: rrdhcp78-120:test_data msb65$ cat ~/bin/test2 #!/bin/sh array2=${1} (5 Replies)
Discussion started by: msb65
5 Replies

4. Shell Programming and Scripting

saving awk value in a bash array variable

hi all i am trying to save an awk value into an array in bash: total=`awk '{sum+=$3} END {print sum}' "$count".txt"` ((count++)) the above statement is in a while loop.. $count is to keep track of file numbers (1.txt,2.txt,3.txt,etc.) i get the following error: ./lines1:... (1 Reply)
Discussion started by: npatwardhan
1 Replies

5. Shell Programming and Scripting

AWK help. how to compare a variable with a data array in AWK?

Hi all, i have a data array as follows. array=ertfgj2345 array=456ttygkd . . . array=errdjt3235 so number or elements in the array can varies depending on how big the data input is. now i have a variable, and it is $1 (there are $2, $3 and so on, i am only interested in $1). ... (9 Replies)
Discussion started by: usustarr
9 Replies

6. Shell Programming and Scripting

AWK help: how to compare array elements against a variable

i have an array call ignore. it is set up ignore=34th56 ignore=re45ty ignore=rt45yu . . ignore=rthg34 n is a variable. I have another variable that i read from a different file. It is $2 and it is working the way i expect. array ignore read and print correct values. in the below if... (2 Replies)
Discussion started by: usustarr
2 Replies

7. Shell Programming and Scripting

Problem using shell variable in awk if condition

Hi friends, I'm having a bit of a problem using shell variable in an awk if statement. Please note that i'm using -v option as listed in many forums but I still don't get it working. Here's my code. Kindly help as I've gone crazy trying to work this out :wall: #!/bin/bash -xv ... (4 Replies)
Discussion started by: vishwas.s
4 Replies

8. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

9. Shell Programming and Scripting

Pass awk array variable to shell

Hi, all suppose I have following myfile (delimited by tab) aa bb cc dd ee ffand I have following awk command: awk 'BEGIN{FS="\t"}{AwkArrayVar_1=$1;AwkArrayVar_2=$2};END{for(i=0; i<NR; i++) print i, AwkArrayVar_1, AwkArrayVar_2,}' myfileMy question is: how can I assign the awk array... (7 Replies)
Discussion started by: littlewenwen
7 Replies

10. Shell Programming and Scripting

How to Assign an shell array to awk array?

Hello All, Can you please help me with the below. #!/bin/bash ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5 EXTRACT_DT:30-SEP-12 VER_NUM:1" ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5... (14 Replies)
Discussion started by: Ariean
14 Replies
gb_trees(3erl)						     Erlang Module Definition						    gb_trees(3erl)

NAME
gb_trees - General Balanced Trees DESCRIPTION
An efficient implementation of Prof. Arne Andersson's General Balanced Trees. These have no storage overhead compared to unbalanced binary trees, and their performance is in general better than AVL trees. This module considers two keys as different if and only if they do not compare equal ( == ). DATA STRUCTURE
Data structure: - {Size, Tree}, where `Tree' is composed of nodes of the form: - {Key, Value, Smaller, Bigger}, and the "empty tree" node: - nil. There is no attempt to balance trees after deletions. Since deletions do not increase the height of a tree, this should be OK. Original balance condition h(T) <= ceil(c * log(|T|)) has been changed to the similar (but not quite equivalent) condition 2 ^ h(T) <= |T| ^ c . This should also be OK. Performance is comparable to the AVL trees in the Erlang book (and faster in general due to less overhead); the difference is that deletion works for these trees, but not for the book's trees. Behaviour is logarithmic (as it should be). DATA TYPES
gb_tree() = a GB tree EXPORTS
balance(Tree1) -> Tree2 Types Tree1 = Tree2 = gb_tree() Rebalances Tree1 . Note that this is rarely necessary, but may be motivated when a large number of nodes have been deleted from the tree without further insertions. Rebalancing could then be forced in order to minimise lookup times, since deletion only does not rebalance the tree. delete(Key, Tree1) -> Tree2 Types Key = term() Tree1 = Tree2 = gb_tree() Removes the node with key Key from Tree1 ; returns new tree. Assumes that the key is present in the tree, crashes otherwise. delete_any(Key, Tree1) -> Tree2 Types Key = term() Tree1 = Tree2 = gb_tree() Removes the node with key Key from Tree1 if the key is present in the tree, otherwise does nothing; returns new tree. empty() -> Tree Types Tree = gb_tree() Returns a new empty tree enter(Key, Val, Tree1) -> Tree2 Types Key = Val = term() Tree1 = Tree2 = gb_tree() Inserts Key with value Val into Tree1 if the key is not present in the tree, otherwise updates Key to value Val in Tree1 . Returns the new tree. from_orddict(List) -> Tree Types List = [{Key, Val}] Key = Val = term() Tree = gb_tree() Turns an ordered list List of key-value tuples into a tree. The list must not contain duplicate keys. get(Key, Tree) -> Val Types Key = Val = term() Tree = gb_tree() Retrieves the value stored with Key in Tree . Assumes that the key is present in the tree, crashes otherwise. lookup(Key, Tree) -> {value, Val} | none Types Key = Val = term() Tree = gb_tree() Looks up Key in Tree ; returns {value, Val} , or none if Key is not present. insert(Key, Val, Tree1) -> Tree2 Types Key = Val = term() Tree1 = Tree2 = gb_tree() Inserts Key with value Val into Tree1 ; returns the new tree. Assumes that the key is not present in the tree, crashes otherwise. is_defined(Key, Tree) -> bool() Types Tree = gb_tree() Returns true if Key is present in Tree , otherwise false . is_empty(Tree) -> bool() Types Tree = gb_tree() Returns true if Tree is an empty tree, and false otherwise. iterator(Tree) -> Iter Types Tree = gb_tree() Iter = term() Returns an iterator that can be used for traversing the entries of Tree ; see next/1 . The implementation of this is very efficient; traversing the whole tree using next/1 is only slightly slower than getting the list of all elements using to_list/1 and traversing that. The main advantage of the iterator approach is that it does not require the complete list of all elements to be built in mem- ory at one time. keys(Tree) -> [Key] Types Tree = gb_tree() Key = term() Returns the keys in Tree as an ordered list. largest(Tree) -> {Key, Val} Types Tree = gb_tree() Key = Val = term() Returns {Key, Val} , where Key is the largest key in Tree , and Val is the value associated with this key. Assumes that the tree is nonempty. map(Function, Tree1) -> Tree2 Types Function = fun(K, V1) -> V2 Tree1 = Tree2 = gb_tree() maps the function F(K, V1) -> V2 to all key-value pairs of the tree Tree1 and returns a new tree Tree2 with the same set of keys as Tree1 and the new set of values V2. next(Iter1) -> {Key, Val, Iter2} | none Types Iter1 = Iter2 = Key = Val = term() Returns {Key, Val, Iter2} where Key is the smallest key referred to by the iterator Iter1 , and Iter2 is the new iterator to be used for traversing the remaining nodes, or the atom none if no nodes remain. size(Tree) -> int() Types Tree = gb_tree() Returns the number of nodes in Tree . smallest(Tree) -> {Key, Val} Types Tree = gb_tree() Key = Val = term() Returns {Key, Val} , where Key is the smallest key in Tree , and Val is the value associated with this key. Assumes that the tree is nonempty. take_largest(Tree1) -> {Key, Val, Tree2} Types Tree1 = Tree2 = gb_tree() Key = Val = term() Returns {Key, Val, Tree2} , where Key is the largest key in Tree1 , Val is the value associated with this key, and Tree2 is this tree with the corresponding node deleted. Assumes that the tree is nonempty. take_smallest(Tree1) -> {Key, Val, Tree2} Types Tree1 = Tree2 = gb_tree() Key = Val = term() Returns {Key, Val, Tree2} , where Key is the smallest key in Tree1 , Val is the value associated with this key, and Tree2 is this tree with the corresponding node deleted. Assumes that the tree is nonempty. to_list(Tree) -> [{Key, Val}] Types Tree = gb_tree() Key = Val = term() Converts a tree into an ordered list of key-value tuples. update(Key, Val, Tree1) -> Tree2 Types Key = Val = term() Tree1 = Tree2 = gb_tree() Updates Key to value Val in Tree1 ; returns the new tree. Assumes that the key is present in the tree. values(Tree) -> [Val] Types Tree = gb_tree() Val = term() Returns the values in Tree as an ordered list, sorted by their corresponding keys. Duplicates are not removed. SEE ALSO
gb_sets(3erl) , dict(3erl) Ericsson AB stdlib 1.17.3 gb_trees(3erl)
All times are GMT -4. The time now is 06:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy