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

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .