The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Increment variable stored in a file solitare123 Shell Programming and Scripting 1 07-09-2008 02:36 AM
Where is the crontab file stored rajbptl UNIX for Advanced & Expert Users 3 01-18-2008 09:46 AM
Outputting formatted Result log file from old 30000 lines result log<help required> vikas.iet Shell Programming and Scripting 5 12-02-2007 10:43 PM
How to store query multiple result in shell script variable(Array) div_Neev Shell Programming and Scripting 4 11-06-2007 08:10 PM
Directory where spooled file is stored babulilly UNIX for Advanced & Expert Users 1 10-22-2002 04:34 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-03-2008
youareapkman youareapkman is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 10
Prase a file and stored the result to an array

Dear all ,

I have a file whose content has the following format:

jboss.web:type=ThreadPool,name=AAAA
jboss.web:type=ThreadPool,name=BBBB

How can I parse this file to get the value of the name of each line (AAAA , BBBB) and store the result to an array ? (array[0] = AAAA , array[1] = BBBB).
Different files will have different total number of lines.

Regards.
  #2 (permalink)  
Old 09-03-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,875
What programming language you are using?
  #3 (permalink)  
Old 09-03-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,309
You can do something like:

Code:
#!/bin/sh

cnt=0

awk -F"=" '{print$3}' file | while read name
do
  arr[$cnt]=$name
  let cnt=cnt+1
done
Regards
  #4 (permalink)  
Old 09-03-2008
RahulJoshi's Avatar
RahulJoshi RahulJoshi is offline
Registered User
  
 

Join Date: Aug 2008
Location: PUNE
Posts: 98
code:
sed -e 's/'^.*='/ /g' filename |awk '{print NR ,$1}'
or
sed -e 's/'^.*='/ /g' filename

this helps u. use in ur for loop
  #5 (permalink)  
Old 09-03-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj - the student
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 596
Try using the below in a loop to assign in an array:

Code:
sed 's/\(.*\)name=\(.*\)/\2/' file
or

Code:
while read line; do echo ${line#jboss.web:type=ThreadPool,name=}; done<file
Closed Thread

Bookmarks

Tags
store array

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0