How to make wc interpret standard in as a file list
find in conjunction with
xargs. The only reason I am recommending
find is to take advantage of the
-print0 option, which separates file names by NULs; this helps avoid issues with file names containing spaces.
find . -maxdepth 1 -type f -print0 | xargs -0 wc
If you want to take the output of a command and use it as an input file list to
wc, you could probably do something like this:
wc $(ls JP*/std*)
ls JP*/std* and its output gets passed as arguments to
xargs might also be useful for you here:
ls JP*/std* | xargs wc
xargs manpage for more detail about how it can be used, as it's quite flexible.
Related videos on Youtube
TTT 6 days
I know that there are other ways to go about this, but I'm looking to be able to make
wcinterpret stdin as a file name or list of file names. For example,
ls JP*/std* | wc
would work the same as
I am guessing it isn't possible to adjust this behavior, but I'm working on a script where this'd make my life a lot easier. Thanks.
TTT over 9 yearsThe input may be coming from a file, but I should be able to pass the path for each to a find statement, so this should still work. Thanks!
derobert over 9 years@TTT The important bit is the
xargs. You don't need the find, the find was just in place of your
ls(with the added feature of -print0). Check the xargs manpage, you'll need to tell it the format of your file.
Kevin over 9 yearsNot whitespace-safe.
Gilles 'SO- stop being evil' over 9 years