-1

I have following problem. I want to print content of several files. Each file is in different directory, and also has same name.

/home/User1/data.txt
/home/User2/data.txt
/home/User3/data.txt

Every file contains single string. I want to achieve following output:

User1 string_from_data.txt
User2 string_from_data.txt
User3 string_from_data.txt

I've tried to use following commend:

find . -iname "data.txt" | xargs cat

but it returns only contents of each data.txt

string_from_data.txt
string_from_data.txt
string_from_data.txt

How to write it properly?

oguz ismail
  • 1
  • 16
  • 47
  • 69
user2178946
  • 9
  • 1
  • 2

1 Answers1

0
find . -iname "file*" -exec sh -c 'dirname $1 | xargs basename; cat $1' _ {} \;
Jeff Jia
  • 13
  • 3