awk small discussion on array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk small discussion on array
# 8  
Old 09-16-2013
Quote:
Originally Posted by Akshay Hegde
I just wanted to know,why I am getting fatal: attempt to use scalar parameter `b' as an array
Because you did not pass the array A1 into it, you passed the string "A1" into it. Variables do not work that way.
# 9  
Old 09-16-2013
Yeah..I agree its string..any alternate solution ???
# 10  
Old 09-16-2013
My general suggestion would be "don't do that"... Almost no language allows this, and it's still ugly in those which can. It's simple to organize your data in any linear structure so it's unnecessary, too.

The usual alternative for these is arrays, especially associative arrays or multidimensional arrays instead of variable variable names, not as well as. A[0,...] instead of A0[...] essentially.
# 11  
Old 09-16-2013
Thank you Corona688.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

HELP - NEED Small Script ( or single awk Command)

Hi All REQUIREMENT:- ========== There is one folder named /data/ds/dpr_ukdw_sys/working/unixfile In that folders there are files are like below CODS_ACTMZ_TRANS_ALL_20150911.TXT CODS_ACTMZ_REF_CTR_ACT_MIL_20150911.TXT CODS_ACTMZ_REF_NHA_ALL_20150911.TXT ... (4 Replies)
Discussion started by: Nagarjuna4347
4 Replies

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

3. Shell Programming and Scripting

Split a large array into small chunks

Hi, I need to split a large array "@sharedArray" into 10 small arrays. The arrays should be like @sharedArray1,@sharedArray2,@sharedArray3...so on.. Can anyone help me with the logic to do so :(:confused: (6 Replies)
Discussion started by: rkrish
6 Replies

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

5. UNIX for Dummies Questions & Answers

AWK - changing first char from small to upper

I need to write script in AWK, changing first char from a line from lower to upper. I found function toupper etc. but have no idea how to sent only first char from every line instead of the whole line. Anyone has any idea? // Sorry for my english:D (8 Replies)
Discussion started by: bbqtoss
8 Replies

6. UNIX for Dummies Questions & Answers

small doubt in awk

Hi Guys, I have a small problem with awk. I want to search { and } at a particular position in a string using awk. I tried echo "hello{hi" | awk '{if(substr($0,6,1)=="{"){print "TRUE"}}' but no success :mad: i know it can be done in many ways and i know them also.. but my... (6 Replies)
Discussion started by: vidyadhar85
6 Replies

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

8. UNIX for Dummies Questions & Answers

A small AWK problem

I have a file tmp.out with contents: 2008-08-09 05:11:01 2008-08-09 08:52:59 2008-08-11 12:08:34 2008-08-11 12:15:40 I want the output to be: 3|0|1|71|2008-08-09 05:11:01|2008-08-30 11:19:28 4|0|1|71|2008-08-09 08:52:59|2008-08-30 11:19:28 5|0|1|71|2008-08-11 12:08:34|2008-08-30 11:19:28... (6 Replies)
Discussion started by: ChicagoBlues
6 Replies

9. Shell Programming and Scripting

Please help to debug a small shell script (maybe AWK problem)?

Hi Buddies, The following is shell scripts which was borrowed from linux box for load average check. it runs good. (this structure is simple, when load average is too high, it will send alert to user) #!/usr/bin/ksh # Set threshold for 1, 5 and 15 minture load avarage # configured for... (4 Replies)
Discussion started by: GreatJerry
4 Replies

10. Shell Programming and Scripting

AWK deifnition and some small code explanation

Could someone give me a quick simple explanation for the AWK command. And also help me to explain the code i have made. I have made some general comments about it myself. I was wondering if people could help me with the rest: awk -F'' 'END { fmt = "%-20s\t%s\t%s\n" ... (0 Replies)
Discussion started by: amatuer_lee_3
0 Replies
Login or Register to Ask a Question