Sponsored Content
Full Discussion: Help how to make awk array
Top Forums Shell Programming and Scripting Help how to make awk array Post 302930355 by dony71 on Friday 2nd of January 2015 02:53:21 PM
Old 01-02-2015
Help how to make awk array

Hi expert,
I'm newbie in awk programming and now I have difficulty how to make awk array in ash shell. I have code below.
As you know ash shell doesn't support array and I cannot install bash
in my embedded environment.
So in order this code to work in ash shell then all array needs to be converted
Problem now while creating array in ash shell :

Code:
   scene[$SCNCNT]=$(echo $line | awk '{ print $2 }')

and calling array in ash shell :

Code:
   echo "MSG~heyu $(echo ${scene[${phone#*~}]})" | tee -a $LOG
   $HEYU $(echo ${scene[${phone#*~}]})

Can somebody help me on this?

Code:
#!/bin/sh

HEYU=/usr/bin/heyu	      # Path to Heyu
SED=/usr/bin/sed
SORTAZ=0                      # If 0, will sort by house code.

get_scenes() {
   SCENES=$($HEYU show usersyns | grep "usersyn")
   if [ "$SORTAZ" -eq "1" ]
    then 
       SCENES=$(echo "$SCENES" | sort)
   fi
   IFS=$(echo -en "\n\b")
   for line in $SCENES
    do
       let SCNCNT=$SCNCNT+1
       scene[$SCNCNT]=$(echo $line | awk '{ print $2 }')
       echo -n "S: " >> $LOG
       echo $line | awk '{ print "SCENE~" $2 "~'$SCNCNT'" }' | sed 's/_/ /g' | \
       sed 's/.*/\L&/; s/[a-z]*/\u&/g' | tee -a $LOG
   done
   IFS=$ORIGIFS
}

set_scene() {
   echo -n "S: " >> $LOG
   echo "MSG~heyu $(echo ${scene[${phone#*~}]})" | tee -a $LOG
   $HEYU $(echo ${scene[${phone#*~}]})
   sleep 1
   get_updates "$DEVICES"
} 

get_scenes
set_scene


Last edited by Scrutinizer; 01-02-2015 at 04:06 PM.. Reason: additional code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

to make 2 lines into 1 line using awk

suppose i have a file AAAHHHHAHH AJJJJAAAAAA AJJJJJAAJJAK AJJAJJAJKKK the output suhd be AAAHHHHAHHAJJJJAAAAAAAJJJJJAAJJAKAJJAJJAJKKK (2 Replies)
Discussion started by: cdfd123
2 Replies

2. Shell Programming and Scripting

awk help to make my work faster

hii everyone , i have a file in which i have line numbers.. file name is file1.txt aa bb cc "12" qw xx yy zz "23" we bb qw we "123249" jh here 12,23,123249. is the line number now according to this line numbers we have to print lines from other file named... (11 Replies)
Discussion started by: kumar_amit
11 Replies

3. Shell Programming and Scripting

Is there anyway to make awk "talks" to DB, say any awk-ODBC tools

Hi all, Is there anyway to make awk talk to DB ? So my awk script reads the data from some text file and eventually those data need to be stored in database. So is there anyway to do it in awk all tohether, say any awk-ODBC tool to make it work? (I really hate to write a cpp/java program... (4 Replies)
Discussion started by: qiulang
4 Replies

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

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

6. Shell Programming and Scripting

Make array from file

I need to create an array from the first line of a file like: a;b;c d;e;f g;h;i In this instance, the array should be (a,b,c). How do I do that? (1 Reply)
Discussion started by: locoroco
1 Replies

7. Shell Programming and Scripting

Reading columns from a text file and to make an array for each column

Hi, I am not so familiar with bash scripting and would appreciate your help here. I have a text file 'input.txt' like this: 2 3 4 5 6 7 8 9 10 I want to store each column in an array like this a ={2 5 8}, b={3 6 9}, c={4 7 10} so that i can access any element, e.g b=6 for the later use. (1 Reply)
Discussion started by: Asif Siddique
1 Replies

8. Shell Programming and Scripting

awk changes to make it faster

I have script like below, who is picking number from one file and and searching in another file, and printing output. Bu is is very slow to be run on huge file.can we modify it with awk #! /bin/ksh while read line1 do echo "$line1" a=`echo $line1` if then echo "$num" cat file1|nawk... (6 Replies)
Discussion started by: mirwasim
6 Replies

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

10. Shell Programming and Scripting

awk - make new line

Hi, I would like to make a new line example like below: "When you post an item you can just delete the files." every 3 words of the above sentence I would like to make a new line like below: " When you post an item you can just delete the files " and after the last line "the... (6 Replies)
Discussion started by: khchong
6 Replies
XmScrollVisible(3X)													       XmScrollVisible(3X)

NAME
XmScrollVisible - A ScrolledWindow function that makes an invisible descendant of a ScrolledWindow work area visible SYNOPSIS
#include <Xm/ScrolledW.h> void XmScrollVisible (scrollw_widget, widget, left_right_margin, top_bottom_margin) Widget scrollw_widget; Widget widget; Dimension left_right_margin; Dimension top_bottom_margin; DESCRIPTION
XmScrollVisible makes an obscured or partially obscured widget or gadget descendant of a ScrolledWindow work area visible. The function repositions the work area and sets the specified margins between the widget and the nearest viewport boundary. The widget's location rela- tive to the viewport determines whether one or both of the margins must be adjusted. This function requires that the XmNscrollingPolicy of the ScrolledWindow widget be set to XmAUTOMATIC. Specifies the ID of the ScrolledWindow widget whose work area window contains an obscured descendant. Specifies the ID of the widget to be made visible. Specifies the margin to establish between the left or right edge of the widget and the associated edge of the viewport. This margin is established only if the widget must be moved horizontally to make it visi- ble. Specifies the margin to establish between the top or bottom edge of the widget and the associated edge of the viewport. This margin is established only if the widget must be moved vertically to make it visible. For a complete definition of ScrolledWindow and its associated resources, see XmScrolledWindow(3X). SEE ALSO
XmScrolledWindow(3X) XmScrollVisible(3X)
All times are GMT -4. The time now is 05:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy