Re: tar ten files each time



At 2009-06-03 09:34PM, "moonhkt" wrote:
Tested on AIX 5.2. Thank a lot

Can not able to using printf "%s\0" *
Can not able to using xargs -0

# printf "%s\n" * | xargs -L 10
a1.txt a2.txt a3.txt a4.txt abc.txt
# printf "%s\n" * | xargs -L 4
a1.txt a2.txt a3.txt a4.txt
abc.txt
[shkdev:/home/ericl6/temp]

You need a way to protect files with spaces. Consider this:

$ ls -1
a file with spaces
file1
file2
file3
file4
this file has spaces

$ printf "%s\n" * | xargs -L 3 perl -e 'print join(",", @ARGV), "\n"'
a,file,with,spaces,file1,file2
file3,file4,this,file,has,spaces

That's no good. How about adding single quotes around %s:

$ printf "'%s'\n" * | xargs -L 3 perl -e 'print join(",", @ARGV), "\n"'
a file with spaces,file1,file2
file3,file4,this file has spaces

Ah, better. Will still have trouble if any of your filenames have a
single quote in them. There's a better technique offered by Stephane
some time ago, but I haven't learned that lesson :(

--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
.



Relevant Pages

  • moving files with embedded whitespace using find -exec
    ... Sorry if it screws up the rest of the message) ... I've reset IFS to just a newline to try and force mv to keep the filename together as the first argument. ... I've also tried using single quotes and double quotes in various combinations around the source and destination, ... xargs does have a nice -0 option to work in conjunction with the -print0 option of find, but I still don't see how that could help without the ability to use in xargs. ...
    (comp.unix.shell)
  • Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?
    ... characters meaningful to the shell. ... % (mydir, mydir)) ... then it will only break if there are single quotes in the file name. ... these names go directly from tar to xargs via a pipe. ...
    (comp.lang.python)
  • Re: How to sort by a field name?
    ... the 1st line contains the field name and to sort by field named "C" ... That's more a database problem than a ahell problem, ... printf "Input file '%s' not found, ... # escape single quotes with an extra single quote ...
    (comp.unix.shell)
  • Re: how to simulate tar filename substitution across piped subprocess.Popen() calls?
    ... However, once he does that, it's simpler to cut out xargs and invoke ... he no longer needs to worry about single quotes. ... That sounds like a sensible plan to me. ...
    (comp.lang.python)