How do I do "ls *.txt | xargs -n 1 cat" in Hotwire?

4 views
Skip to first unread message

yzhh

unread,
Jun 26, 2008, 5:52:16 AM6/26/08
to Hotwire Shell
I know there is "apply", but it does not provide options and "ls *.txt
| apply cat" gives error. Looks like that result of "ls *.txt" can not
be applyed (turned into strings) as arguments to another command.

Well, if it is meant to be done in other ways, please tell me. (Let's
suppose "cat" may be substituted by anything else that makes sense.)

Colin Walters

unread,
Jun 26, 2008, 11:07:52 AM6/26/08
to Hotwire Shell
Hi,

On Jun 26, 5:52 am, yzhh <yezong...@gmail.com> wrote:
> I know there is "apply", but it does not provide options and "ls *.txt
> | apply cat" gives error. Looks like that result of "ls *.txt" can not
> be applyed (turned into strings) as arguments to another command.

Right, the result of "ls" is going to be some subclass of File. So
what you want to do here is:

ls *.txt | prop path | apply cat

What the "prop path" does is extract the "path" property of each File
object.

yzhh

unread,
Jun 26, 2008, 1:00:35 PM6/26/08
to Hotwire Shell


On 6月26日, 下午11时07分, Colin Walters <cgwalt...@gmail.com> wrote:

> Right, the result of "ls" is going to be some subclass of File. So
> what you want to do here is:
>
> ls *.txt | prop path | apply cat
>

Thank you. But I still have not get the "-n 1" option. For xargs "-n
1" means it will call "cat" multiple times, each time with one
argument (one word) from the pipe. Suppose we substitute "cat" with
some other program that accepts just one argument, the result is
different with/without "-n 1".

BTW, map(lambda x: cat(x.path), ls("*.txt")) looks much natural to me,
especially the 'x.path' part. I think I partly understand why it is
not done this way in Hotwire.
Reply all
Reply to author
Forward
0 new messages