Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-15-2008, 09:05 PM   #1
LQ Newbie
Registered: Mar 2008
Posts: 4

Rep: Reputation: 0
Reg Makefile : Read file : for loop

I have following code in my

make file :

	rm -f $@ ;
	for file in $(wildcard t*_diff.txt); do \
			echo "$${file}	1	2	$${file}	0" >> $@ ; \
	done ;
My goal is to modify this code,

a) it should read in the file "ids.txt" : which will have all the different file ids, for each id in the file it should

do echo "$${file} 1 2 $${file} 0" >> $@ ; \

Making short instead of *.diff.txt now I want to read in the file which has all the ids. I don't know how read in file in Makefiles into array ..

Thanks a lot.
Old 03-16-2008, 07:27 AM   #2
Registered User
Registered: Mar 2008
Posts: 104

Rep: Reputation: 15
using backticks in Makefile

My solution would go like this:

ABCFILE=`cat abcfile`
	rm -f $@ ;
	for file in $(ABCFILE); do \
	echo "$${file}	1	2	$${file}	0" >> $@ ; \
	done ;
My input file named 'abcfile' simply contains the line 'a b c' where everything between whitespaces will become a token. The new 'batch.txt' output looks like this:

a	1	2	a	0
b	1	2	b	0
c	1	2	c	0
Is this what you wanted to achieve?

Hope this helps,

Linux Archive

Last edited by simplicissimus; 04-02-2008 at 04:34 AM.
Old 03-16-2008, 12:57 PM   #3
LQ Newbie
Registered: Mar 2008
Posts: 4

Original Poster
Rep: Reputation: 0

Thanks a lot.

The original Makefile is big, but yeap for this snippet of code thats what I wanted.

Thanks a lot.


Last edited by mogra; 03-16-2008 at 01:08 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 03:49 PM
BASH: Read entire file line in for loop clinton Programming 16 04-18-2013 12:06 PM
Makefile issue: "Makefile.src: File not found" m3rkury Linux - Software 1 02-22-2007 10:15 PM
while READ loop problem caps_phisto Linux - General 3 02-05-2007 09:58 AM
reg loop back adapater anilchow Linux - Security 1 10-02-2003 06:01 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:57 AM.

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