I am doing
grep -l 0000201290 ServerApplication.log* | xargs cp j231110_4/
but it tells me
cp: can't stat 'ServerApplication.log.5/j231110_4': Not a directory
Which is correct, it should be 'j231110_4/ServerApplication.log.5', because 'j231110_4' is a directory and 'ServerApplication.log.5' is a file I want to be copied in directory 'j231110_4'.
How can I copy grep output list of files to some dir?
Have tried How to pipe output from grep to cp? but it does not work. I guess mobaXterm works differently than linux.
Your arguments are ending up in the wrong order. Use xargs' -I for a placeholder.
This is pretty forgiving as long as your replacement string doesn't show up anywhere else in your command.
ah, BusyBox...
Try this then: use
cp
's-t
option to make the argument order irrelevant.It should work as long as you do NOT have any weird characters like embedded spaces in your filenames - looks likely, but I try to make as few assumptions as possible. I ran a quick test on a HackerRank BusyBox v1.36.1, so hopefully v1.22.1 will respect
-t
.If you do have odd characters... try this.
If none of those work for whatever reason, fall back to simplest:
This will still fail on embedded newlines, so check your data.
Or (again, as long as there are no embedded surprises) just