3

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

brucezepplin
  • 9,202
  • 26
  • 76
  • 129

1 Answers1

4

You can do:

cut -d ' ' -f2 | xargs -I {} bash -c 'cat *{}.txt'
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    @ anubhava. thank you. if I had -f2-3 and passed them, how would I call f2 and f3 explicitly in xargs? it seems that using the {} notation would force them both. – brucezepplin Mar 30 '15 at 21:24
  • what i mean is, can i do xargs - I {} {} bash -c 'echo {1} cat*{2}.txt' ? – brucezepplin Mar 30 '15 at 21:39
  • 1
    You can use `xargs -n 2 bash -c 'echo "<$0><$1>"'` where `$0` and `$1` are first and second arguments. – anubhava Mar 30 '15 at 21:45