Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-26-2004, 08:31 AM   #1
LQ Newbie
Registered: Apr 2004
Posts: 19

Rep: Reputation: 0
How to return values into an array using awk


Is it possible to rewrite this while-loop to make it work?

while i < 10
myArr[i]=`awk -v var=$line '{ lines[$0]++ } END { for( line in lines ) print line }' myFile`
i = `expr $i + 1`

Am I on the right track at all? This syntax is complicated..
I want the array to be filled up with the 10 first records of my file.

Old 05-01-2004, 10:05 PM   #2
Registered: Oct 2002
Location: Bangalore
Distribution: Gentoo Linux
Posts: 96

Rep: Reputation: 16

I'm assuming that you have a recent version of bash or such. How about this?

set -A myarr `awk -v var=$line '{if (NR == var) {line=$0; exit;}} END {print line}' myFile`


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
awk: How can I return a specified record dimsh Linux - Newbie 4 09-24-2005 11:36 AM
'load average' return values from sysinfo() bulliver Programming 4 04-05-2005 10:02 PM
How to use return values from system functions? kpachopoulos Programming 2 07-30-2004 03:09 AM
Add values using awk Helene Programming 4 04-21-2004 06:30 PM
How can get values return from a system call quenn Programming 1 09-16-2003 11:05 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:43 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration