[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: A quick Q: how do I command something in large amount



>>>>> Jochen Spieker <ml@well-adjusted.de> writes:
>>>>> lina:

 >> for i in a b c
 >> do
 >> txt2pdf -input i.txt -out i.pdf
 >> done

 > You almost nailed it:

 > for i in a b c ; do
 >   txt2pdf -input ${i}.txt -out ${i}.pdf
 > done

 > Instead of listing the files manually, you can use '*' as a wildcard.
 > But that only works if your filenames don't contain whitespace.

	Whitespace is not a problem as long as one remembers to
	double-quote Shell $ubstitutions, like:

   for i in a b c ; do
     txt2pdf -input "${i}.txt" -out "${i}.pdf"
   done

 > A more robust solution:

 > find /dir/to/files -type f -print0 | \
 >     xargs -0 -I§ txt2pdf -input § -out §.pdf

	find(1) has -exec, which simplifies the above to:

   find /dir/to/files -type f \
     -exec txt2pdf -input {} -out {}.pdf \; 

 > This will produce filenames like "a.txt.pdf", but you get the idea.

 > xargs hast the additional benefit that you can use multiple cores at
 > once when using the -P option.

 >> sorry I can only think of the debian user list to ask now.

	There's also the news:comp.unix.shell newsgroup, dedicated to
	the Shell language.

	I haven't ever tried it, but I guess that using Google Groups
	[1] shouldn't be much different to using Google Mail.

[1] http://groups.google.com/group/comp.unix.shell/

-- 
FSF associate member #7257	2 days left to Software Freedom Day
http://sf-day.org/	Event at Altai State University: http://sfd.am-1.org/


Reply to: