AllIsHackedOff

Just a memo, just a progress

MacのxargsのJ option (replacerを使う記法)

command  | xargs -i cp {} target_dir

的なことがやりたかったがどうもMacのxargsだとだめらしい(これだからMacは…)

manを開くと下記が記載されていたので事なきを得た。

     -J replstr
             If this option is specified, xargs will use the data read from standard input to replace the first occurrence of replstr instead of appending that data after all other arguments.  This option will not
             affect how many arguments will be read from input (-n), or the size of the command(s) xargs will generate (-s).  The option just moves where those arguments will be placed in the command(s) that are
             executed.  The replstr must show up as a distinct argument to xargs.  It will not be recognized if, for instance, it is in the middle of a quoted string.  Furthermore, only the first occurrence of the
             replstr will be replaced.  For example, the following command will copy the list of files and directories which start with an uppercase letter in the current directory to destdir:

                   /bin/ls -1d [A-Z]* | xargs -J % cp -rp % destdir