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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.