LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 08-27-2006, 09:13 AM   #1
pawan_songara
LQ Newbie
 
Registered: Aug 2006
Posts: 6

Rep: Reputation: 0
String Parser


I want to parse a string in a loop
eg A:B:C
E:F:G:H
and put them in different variable
attr1 = A
attr2 = B
attr3 = C
attr4 = D
.
.
/* do processing with attr1, attr2, attr3 and attr4 */

then go to next line E:F:G:H and again assign attr1/attr2/attr3/attr4 with E,F,G and H

Strings I am reding from file line by line. In a line, string can be of any size
for example
A:B:C
E:F:G:H
I:J:K:L:M:N

Therefore after reading a line I want to traverse it till end of line and put strings in different variable depending upon no of strings available in that line(attr1/2/3...)

Could you please guide how should be my bash shell script
 
Old 08-27-2006, 09:58 AM   #2
Centinul
Member
 
Registered: Jun 2005
Distribution: Gentoo
Posts: 552

Rep: Reputation: 30
I don't know enough to give you the actual command but if all your strings are delimited by a ":" then you can use AWK and specify the ":" as a delimiter and print out each individual string in a for loop. Then you can use BASH to create a for loop for each line. Or something along those lines
 
  


Reply



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
checking for XML::Parser... configure: error: XML::Parser perl module is required for kornerr Linux - General 11 11-16-2008 07:24 AM
DTD's Parser? trscookie Linux - Software 0 11-07-2005 04:55 PM
XML Parser bulkman Linux - Software 6 04-29-2005 07:01 AM
URI parser nodger Programming 1 05-03-2004 10:56 AM
java test if string in string array is null. exodist Programming 3 02-21-2004 01:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:01 AM.

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