brucezepplin
brucezepplin

Reputation: 9752

pipe result of cut to next argument and concat to string

I have something like:

cut -d ' ' -f2 | xargs cat *VAR_HERE.ss

where I want to use the result of cut as a variable and concat the output of cut between * and . so that cat will use the name to output the appropriate file. for example if the result of cut is:

$ cut -d ' ' -f2
001

I essentially want the second command to do:

$ cat *001.txt

I have seen xargs been used, but I am struggling to find out how to use it to explicitly call the output of cut, rather than assuming the second command only requires the exact output. obviously here I want to concat the output of cut to a string.

thanks

Upvotes: 3

Views: 3090

Answers (1)

anubhava
anubhava

Reputation: 785058

You can do:

cut -d ' ' -f2 | xargs -I {} bash -c 'cat *{}.txt'

Upvotes: 4

Related Questions