Jump to content

Merge multiple text files into one file

From LemonWiki共筆
Revision as of 16:24, 30 January 2020 by Unknown user (talk) (Created page with "Step 1: check the last line of text file is newline<ref>[https://stackoverflow.com/questions/34943632/linux-check-if-there-is-a-newline-at-the-end-of-a-fil...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Step 1: check the last line of text file is newline[1]

Step 2: Merge the content

  • copy *.txt > bundle.txt or copy file1.txt file2.txt > bundle.txt on Win
  • cat *.txt > bundle.txt or cat file1.txt file2.txt > bundle.txt on Linux [2][3]

Step 3: (optional) Remove the duplicated lines

  • sort -us -o bundle_unique.txt bundle.txt[4] OS: Linux , cygwin of Win "-u means Unique keys; -s means stable sort; -o means output" quoted from sort manual.