The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Regardign strtok() output directing to 2-D string array SankarV High Level Programming 3 04-28-2008 06:48 AM
bash:awk output into an array phamp008 Shell Programming and Scripting 2 03-16-2008 02:14 AM
create array holding characters from sring then echo array. rorey_breaker Shell Programming and Scripting 5 09-28-2007 05:42 AM
output of an array ragha81 Shell Programming and Scripting 3 03-22-2007 01:30 PM
formating array file output using perl seismic_willy Shell Programming and Scripting 4 03-21-2007 11:23 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-19-2007
Registered User
 

Join Date: Oct 2007
Posts: 43
move output of awk to array

Hi experts,

I have a the following awk command,

awk '{print $1}' /users/jon/list4.txt. The output is

123
787
888
...
...

I want to move the output to array using shell programming.

My shell is tcsh.

Is it possible to move to array using shell porg? I know its possible in perl.

Let me know

Thanks

Amit
Reply With Quote
Forum Sponsor
  #2  
Old 12-19-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
with this data would be populated in the array

Code:
awk '{ arr[$1] }' filename
Reply With Quote
  #3  
Old 12-19-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Code:
# array=$(awk '{print $1}' /users/jon/list4.txt)
# for items in $array; do echo $items; done
Reply With Quote
  #4  
Old 12-19-2007
Registered User
 

Join Date: Oct 2007
Posts: 43
Quote:
Originally Posted by matrixmadhan View Post
with this data would be populated in the array

Code:
awk '{ arr[$1] }' filename
Hi madhan,
Thanks much for the help.
One doubt, How do I print the array? if I use this

awk '{ arr[$1] }' filename

Thank
Amit
Reply With Quote
  #5  
Old 12-19-2007
Registered User
 

Join Date: Oct 2007
Posts: 43
Quote:
Originally Posted by ghostdog74 View Post
Code:
# array=$(awk '{print $1}' /users/jon/list4.txt)
# for items in $array; do echo $items; done
I am getting the following error,
when I executed,

# array=$(awk '{print $1}' /users/jon/list4.txt)
# for items in $array; do echo $items; done


syntax error at line 21: `array=$' unexpected
Reply With Quote
  #6  
Old 12-19-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Code:
array=`awk '{print $1}' /users/jon/list4.txt`
Reply With Quote
  #7  
Old 12-19-2007
Registered User
 

Join Date: Oct 2007
Posts: 43
Quote:
Originally Posted by ghostdog74 View Post
Code:
array=`awk '{print $1}' /users/jon/list4.txt`
Hi,

Thanks again, one more doubt,
How do I access the value in array(6).

Thx
amit
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0