awk: reading into an array and then print the value corresponding to index


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk: reading into an array and then print the value corresponding to index
# 8  
Old 06-24-2009
Quote:
Originally Posted by akshaykr2
I am getting command not found. All I did was replace nawk with gawk. I do not have nawk.
ok then - run with either awk or gawk.
# 9  
Old 06-24-2009
I did! its not working
# 10  
Old 06-24-2009
Quote:
Originally Posted by akshaykr2
I did! its not working
My crystal ball is being repaired, so please elaborate.
# 11  
Old 06-24-2009
$ gawk'{FNR==NR {arr[FNR]=$1; next} $1==arr[FNR]}' opnoise opwflightno > opwono
ise
bash: gawk{FNR==NR {arr[FNR]=$1; next} $1==arr[FNR]}: command not found

This is what I got
# 12  
Old 06-24-2009
Quote:
Originally Posted by akshaykr2
Code:
$ gawk'{FNR==NR {arr[FNR]=$1; next} $1==arr[FNR]}' opnoise opwflightno > opwono
ise
bash: gawk{FNR==NR {arr[FNR]=$1; next} $1==arr[FNR]}: command not found

This is what I got
You're using a different command ...,
please re-read vgersh99's post.
# 13  
Old 06-24-2009
Quote:
Originally Posted by akshaykr2
$ gawk'{FNR==NR {arr[FNR]=$1; next} $1==arr[FNR]}' opnoise opwflightno > opwono
ise
bash: gawk{FNR==NR {arr[FNR]=$1; next} $1==arr[FNR]}: command not found

This is what I got
Once again - try going through this thread and find what's been suggested.
Good luck!
# 14  
Old 06-24-2009
I realized that you had not used curly brackets. The command runs, but the file generated(opwonoise) does not have anything in it.

Can you please explain the command?

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Index problem in associate array in awk

I am trying to reformat the table by filling any missing rows. The final table will have consecutive IDs in the first column. My problem is the index of the associate array in the awk script. infile: S01 36407 53706 88540 S02 69343 87098 87316 S03 50133 59721 107923... (4 Replies)
Discussion started by: yifangt
4 Replies

2. Shell Programming and Scripting

awk print in one line after reading textfile with paragraphs

Hello everybody I have a text file which has the following format: nmm "text20140601.033954text" "text" "text" "text" , ... , "text" "text" , ... , Lat 36.3247 Lon 16.0588 Depth 8 "text", ... , "text" "text", ..., CovXX 1.65 CovYY 2.32 CovZZ 1.2 "text" , ..., "text nmm ... (6 Replies)
Discussion started by: phaethon
6 Replies

3. UNIX for Dummies Questions & Answers

How To Print Array in awk?

Hello, May i please know how do i print the array using awk script. I am using below shell script to start with but not working. #!/bin/bash LOADSTATUS="Line 0" LOADSTATUS="Line 1" LOADSTATUS="Line 2" LOADSTATUS="Line 3" LOADSTATUS="Line 4" awk ' BEGIN { Your File Load Status }... (1 Reply)
Discussion started by: Ariean
1 Replies

4. Shell Programming and Scripting

awk Search Array Element Return Index

Can you search AWK array elements and return each index value for that element. For example an array named car would have index make and element engine. I want to return all makes with engine size 1.6. Array woulld look like this: BMW 1.6 BMW 2.0 BMW 2.5 AUDI 1.8 AUDI 1.6 ... (11 Replies)
Discussion started by: u20sr
11 Replies

5. UNIX for Dummies Questions & Answers

awk: syntax for "if (array doesn't contain a particular index)"

Hi! Let's say I would like to convert "1", "2", "3" to "a", "b", "c" respectively. But if a record contains other number then return "X". input: 1 2 3 4 output: a b c X What is the syntax for: if(array doesn't contain a particular index){ then print the value "X" instead} (12 Replies)
Discussion started by: beca123456
12 Replies

6. Shell Programming and Scripting

how to search array and print index in ksh

Hi, I am using KSH shell to do some programming. I want to search array and print index value of the array. Example.. nodeval4workflow="DESCRIPTION ="" ISENABLED ="YES" ISVALID ="YES" NAME="TESTVALIDATION" set -A strwfVar $nodeval4workflow strwfVar=DESCRIPTION=""... (1 Reply)
Discussion started by: tmalik79
1 Replies

7. Shell Programming and Scripting

awk reading many fields to array

I want to read $3,$4,$5,$6,$7 of fileA in array and when fileb $1 = fileA $4 the i want to print array and few fields from fileB. This should work but has some syntax error. nawk -F, 'FNR==NR{a=;next} a{print a}' fileB fileA Appreciate if someone can correct this. (2 Replies)
Discussion started by: pinnacle
2 Replies

8. Shell Programming and Scripting

awk array index help

$ cat file.txt A|X|20 A|Y|20 A|X|30 A|Z|20 B|X|10 A|Y|40 Summing up $NF based on first 2 fields, $ awk -F "|" 'BEGIN {OFS="|"} { sum += $NF } END { for (f in sum) print f,sum } ' file.txt o/p: A|X|50 A|Y|60 A|Z|20 (4 Replies)
Discussion started by: uwork72
4 Replies

9. UNIX for Dummies Questions & Answers

wh inode index starts from 1 unlike array index (0)

brothers why inode index starts from 1 unlike array inex which starts from 0 its a question from the design of unix operating system of maurice j.bach i need to know the answer urgently...someone help please (1 Reply)
Discussion started by: sairamdevotee
1 Replies

10. Filesystems, Disks and Memory

why the inode index of file system starts from 1 unlike array index(0)

why do inode indices starts from 1 unlike array indexes which starts from 0 its a question from "the design of unix operating system" of maurice j bach id be glad if i get to know the answer quickly :) (0 Replies)
Discussion started by: sairamdevotee
0 Replies
Login or Register to Ask a Question