开发者

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

开发者 https://www.devze.com 2023-02-08 02:35 出处:网络
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 开发者_StackOverflow社区to do something like this:

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 开发者_StackOverflow社区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

0

精彩评论

暂无评论...
验证码 换一张
取 消