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 01: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 12:30 PM
formating array file output using perl seismic_willy Shell Programming and Scripting 4 03-21-2007 10:23 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
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 (permalink)  
Old 12-19-2007
Technorati Master
 

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

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

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

Join Date: Sep 2006
Posts: 1,444
Code:
array=`awk '{print $1}' /users/jon/list4.txt`
Reply With Quote
  #7 (permalink)  
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 UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:10 PM.


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

Content Relevant URLs by vBSEO 3.2.0