Bash cat files in a directory into one file inserting filename before content

StackOverflow https://stackoverflow.com/questions/4885458

  •  28-10-2019
  •  | 
  •  

سؤال

I have a directory of txt files to cat into another file. But I need to put a header before the content of each file. Specifically, I would like to do something like this:

---------------- <FILENAME> ----------------
content
---------------- <FILENAME2> ---------------
content

Actually I don't need all the "------------" before and after the filename, but it would be nice.

Thank you for your time ;)

هل كانت مفيدة؟

المحلول

for f in *.txt; do echo "----------------<$f>----------------"; cat "$f"; done >> OUTPUT_FILE

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top