SaiKiran
SaiKiran

Reputation: 6504

How to create a file with file_name as the output of present command?

Problem

I have a file which is present in /home/user/Samples/ folder now i have a seperate folder /home/user/Reports/. Suppose i have a sample DOG.zip file in Samples folder, Now i want to generate a report of this sample and store it in Reports folder and name it as MD5 of the file

What i did

cd /home/user/Samples/
md5sum DOG.zip | xargs touch ../Reports/{}

But this is producing {} file in Reports folder but not a empty file with the md5 as file name.

Any suggestion on how to solve this problem?

Upvotes: 0

Views: 77

Answers (1)

glenn jackman
glenn jackman

Reputation: 247012

You need to add -i to xargs to "enable" the {} placeholder:

$ seq 10 | xargs echo foo{}
foo{} 1 2 3 4 5 6 7 8 9 10
$ seq 10 | xargs -i echo foo{}
foo1
foo2
foo3
foo4
foo5
foo6
foo7
foo8
foo9
foo10

Upvotes: 1

Related Questions