Sponsored Content
Top Forums Shell Programming and Scripting using an awk internal variable as parameter for an external array Post 302550303 by MotAah on Thursday 25th of August 2011 09:12:40 AM
Old 08-25-2011
Question using an awk internal variable as parameter for an external array

Hello,

I am running a bash script under linux which first defines an CA-array like
Code:
j=0
num1=120.00
num2=10.00
until [$j -gt 5 ]
do
  CA[$j]='echo $num1 + $j*$num2'
  j=$[$j+1]
done

within the later awk section of this same script I want to read data from a file. If the value of the second column is equal to the value of CA[0 to 5] the array MF[0 to 5] should read the value from column 59:
Code:
awk '
BEGIN {
  ...
  i=0
  while ( i<5 ) {
    if ( match($2,/^'${CA[1]}'/) ) { MF[i] = $59 }
      i = i + 1
  }
}
END ' ${FILE}

As long in the bold written part the parameter of the array is fixed to certain value (here "1") the script works fine. In later stage I do want to read dozend of lines from the file and not only 5!

Does anyone know how I do have to change the script ('${CA[1]}') in order to have "i" of the awk loop to define the parameter fo the external array CA? Any help or work arround is appreciated.

Regards,

MotAah

Last edited by Scott; 08-25-2011 at 10:14 AM.. Reason: Code tags
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk help (external variable)

i need help with an awk question. i am looking to have an external variable be defined outside of awk but used in awk. so if we have fields $1, $2, $3 so on and so forth, i would like to be able to dictate what field is being printed by something like $. so if i had a counter called test, make it 3... (8 Replies)
Discussion started by: pupp
8 Replies

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

3. Shell Programming and Scripting

If statement in awk with external variable

So I have a if statement inside an awk to check if $2 of a awk equals a specific IP but the test fails. So here is what I have. # !/bin/sh echo "Enter client ID" read ID echo "Enter month (01, 02, 03)" read month echo "Enter day (03, 15)" read day echo "Enter Year (07, 08)" read... (6 Replies)
Discussion started by: doublejz
6 Replies

4. Shell Programming and Scripting

Insert external variable in a AWK pattern

Dear all, ¿How can i insert a variable in a AWK pattern? I have almost succeeded in solving a puzzle with AWK but now i want to make a script. Let me explain. cat file.txt | awk 'BEGIN {RS="\\n\\n"} /tux/ { print "\n"$0 }' I know that this command makes right what i want to do, but mi... (8 Replies)
Discussion started by: antuan
8 Replies

5. Shell Programming and Scripting

[awk] - how to insert an external variable

I want to incorporate the variable in the for statement as a column of my processed file. In the INCORRECT example below, it is $i which corresponds to the i in my for loop: for i in x86_64 i686; do awk '{ print $1" "$4" "$5" "$i }'awk $file-$i > processed-$i.log doneThanks! (3 Replies)
Discussion started by: graysky
3 Replies

6. Shell Programming and Scripting

How can we assign value to an array variable from an external file?

is it possible to assign value to an array variable from an external file?? if yes then how?? I am using below code but its not working. #!bin/bash myarray < file_name echo ${mayarray} (6 Replies)
Discussion started by: mukulverma2408
6 Replies

7. Shell Programming and Scripting

Help needed with awk external variable

I'm trying to get the universities result data into different file, where the $9 contains unversity field and field7,4 & 5 contains the keys to sort the students by marks. How to use uni variable to match against $9 inside awk? c=0 for uni in `cat /tmp/global_rank| awk -F ',' '{print... (1 Reply)
Discussion started by: InduInduIndu
1 Replies

8. Shell Programming and Scripting

Passing external variable to awk

Hi, I am trying to write a bash script in which I need to pass a external variable to the awk program. I tired using -v but it not accepting the value. Here is my sample code. #!/usr/bin/bash ###################################################################################### ####... (5 Replies)
Discussion started by: jpkumar10
5 Replies

9. Red Hat

Disk in Linux machine are internal or external

How to check whether the disk in linux machine are internal or external ( from nas or san). How to identify internal(local) and external disks. Following are some details of my server. Thanks. #df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 15G 3.5G 10G... (2 Replies)
Discussion started by: salmanraza
2 Replies
wxSizerFlags(3erl)					     Erlang Module Definition						wxSizerFlags(3erl)

NAME
wxSizerFlags - See external documentation: wxSizerFlags. DESCRIPTION
See external documentation: wxSizerFlags . DATA TYPES
wxSizerFlags() : An object reference, The representation is internal and can be changed without notice. It can't be used for comparsion stored on disc or distributed for use on other nodes. EXPORTS
new() -> wxSizerFlags() Equivalent to new([]) . new(Options::[Option]) -> wxSizerFlags() Types Option = {proportion, integer()} See external documentation . align(This::wxSizerFlags(), Alignment::integer()) -> wxSizerFlags() See external documentation . border(This::wxSizerFlags()) -> wxSizerFlags() Equivalent to border(This, []) . border(This::wxSizerFlags(), Options::[Option]) -> wxSizerFlags() Types Option = {direction, integer()} See external documentation . border(This::wxSizerFlags(), Direction::integer(), BorderInPixels::integer()) -> wxSizerFlags() See external documentation . center(This::wxSizerFlags()) -> wxSizerFlags() See external documentation . centre(This::wxSizerFlags()) -> wxSizerFlags() See external documentation . expand(This::wxSizerFlags()) -> wxSizerFlags() See external documentation . left(This::wxSizerFlags()) -> wxSizerFlags() See external documentation . proportion(This::wxSizerFlags(), Proportion::integer()) -> wxSizerFlags() See external documentation . right(This::wxSizerFlags()) -> wxSizerFlags() See external documentation . destroy(This::wxSizerFlags()) -> ok Destroys this object, do not use object again AUTHORS
<> wxErlang 0.98.9 wxSizerFlags(3erl)
All times are GMT -4. The time now is 02:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy