Concatenate multiple files but include filename as section headers

前端 未结 20 1714
粉色の甜心
粉色の甜心 2020-12-12 09:08

I would like to concatenate a number of text files into one large file in terminal. I know I can do this using the cat command. However, I would like the filename of each fi

20条回答
  •  被撕碎了的回忆
    2020-12-12 09:17

    When there is more than one input file, the more command concatenates them and also includes each filename as a header.

    To concatenate to a file:

    more *.txt > out.txt
    

    To concatenate to the terminal:

    more *.txt | cat
    

    Example output:

    ::::::::::::::
    file1.txt
    ::::::::::::::
    This is
    my first file.
    ::::::::::::::
    file2.txt
    ::::::::::::::
    And this is my
    second file.
    

提交回复
热议问题