in reply to how to write a perl one liner?

How about a bash one liner?

for f in `cat deletefiles.txt` ; do p4 delete "$f" ; done
Or if p4 can take multiple args file names,
p4 delete `cat deletefiles.txt`

Note: Both assume the file names have no shell characters in them (e.g. spaces, "*"). I'm sure that restriction can be eliminated pretty simply, though. Anyone care to enlighten?

Update: And the answer is:

xargs -d \n p4 delete < deletefiles.txt

I think it needs a -n 1 in there if p4 delete can only take one file name at a time.

See xargs.

Replies are listed 'Best First'.
Re^2: how to write a perl one liner?
by ambrus (Abbot) on Mar 08, 2011 at 14:02 UTC

    Don't forget

    while read f; do p4 delete "$f"; done < deletefiles.txt

      I looked at it, but abandoned it when I remembered xargs. It has the same problem as my earlier solutions unless you unset env var IFS. (I think prefixing the whole thing with "IFS=" will do the trick.)

      Additionally, I think xargs will report non-zero exit codes, whereas the bash loop solutions don't without more code.

        It has the same problem as my earlier solutions unless you unset env var IFS.

        I can't see how IFS would figure in this. The read builtin is passed only one name so it will read all of the line (except the newline) into a single variable, and as we double-quote that variable later, it's always passed as a single argument to the command.

        Additionally, I think xargs will report non-zero exit codes, whereas the bash loop solutions don't without more code.

        That's true, yes.

Re^2: how to write a perl one liner?
by perl_mystery (Beadle) on Mar 08, 2011 at 08:43 UTC

    Seems like there is no -d option.I get the following output

    OUTPUT:- Z:>xargs -d \n p4 delete < deletefiles.txt xargs: illegal option -- d Usage: xargs [-0prtx] [-e[eof-str]] [-i[replace-str]] [-l[max-lines]] [-n max-args] [-s max-chars] [-P max-procs] [--null] [--eof[=eo +f-str]] [--replace[=replace-str]] [--max-lines[=max-lines]] [--interact +ive] [--max-chars=max-chars] [--verbose] [--exit] [--max-procs=max-p +rocs] [--max-args=max-args] [--no-run-if-empty] [command [initial-arg +uments]]
      No, seems like there's no -d option in yours.

      Also, that doesn't look like a bash prompt. If you're going to switch shell, you'll also have to convert the command for the new shell. Does your shell convert «\n» to a newline? Although I think -d would also accept the two character string as equivalent.