0

I want to print the filenames and contents for each file in order. I tried this ls -1 after* | (echo;cat) - This only lists the files, does not cat the contents of the files. I also tried ls -1 after* | (echo; xargs cat) - This only cats the contents, does not echo their paths. I would like to see something like

filename1
filename1_contents
filename2
filename2_contents

1 Answers1

2

There is no such option to cat. In bash shell:

for file in after*; do echo "$file"; cat "$file"; done

The file names will be sorted by default. See man bash for more on for loops.

Quasímodo
  • 18,865
  • 4
  • 36
  • 73
spinkus
  • 491