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 05-04-2012, 10:50 AM   #1
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 76

Rep: Reputation: 5
Unhappy Separating words from a string in Make


Hi,

I have a problem where I need to seperate words out of a string from inside a makefile.
for eg:

Commandline:
Quote:
make MOD="word1 word2 word3"
Inside makefile I need to assign these values to a variables as
Quote:
VAR+=word1
VAR+=word2
VAR+=word3
For this I need to parse the string? How to do it?

-Sree

Last edited by sree_ec; 05-04-2012 at 10:51 AM.
 
Old 05-04-2012, 02:02 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082Reputation: 2082
$(word n,text):
Quote:
Returns the nth word of text. The legitimate values of n start from 1. If n is bigger than the number of words in text, the value is empty. For example,
$(word 2, foo bar baz)
returns ‘bar’.

Code:
VAR+=$(word 1, $(MOD))
VAR+=$(word 2, $(MOD))
VAR+=$(word 3, $(MOD))
 
1 members found this post helpful.
Old 05-06-2012, 03:16 PM   #3
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 76

Original Poster
Rep: Reputation: 5
Quote:
Originally Posted by ntubski View Post
$(word n,text):



Code:
VAR+=$(word 1, $(MOD))
VAR+=$(word 2, $(MOD))
VAR+=$(word 3, $(MOD))
Thanks for your help!!
 
  


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
Creating String from words in a file deepakthaman Linux - Newbie 22 09-16-2009 05:15 PM
Creating String from words in a file deepakthaman Programming 1 09-15-2009 09:24 AM
[SOLVED] Bash scripting, separating variable from string text emmalg Linux - Newbie 3 06-26-2009 03:31 AM
separating words cxel91a Programming 14 04-29-2003 01:05 PM

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

All times are GMT -5. The time now is 12:24 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