Combine txt files

I have more than 100 text files and would like to combine them into on single text file or other kind,

ex HTML or pdf

Is it possible ?

MacBook Air 15″

Posted on Sep 20, 2023 1:14 PM

Reply
5 replies

Sep 21, 2023 7:01 AM in response to Bomiboll

Put all of the text files in a folder on your Desktop. Ensure that each has a .txt extension. Then, launch the Terminal application, and enter the following where the folder theTextFiles is a placeholder for your name choice. The >> is UNIX for concatenate.


cd ~/Desktop/theTextFiles
/usr/bin/pr *.txt >> ../combined_text.txt


That pr command by default, will produce individual page headers bearing the name of the text file and its page number in this format:


Sep 20 18:09 2023 apple.txt Page 1


Sep 21, 2023 6:55 AM in response to Bomiboll

Put the line next to '& return' in the script:


set the_text to ""

tell application "Finder"

repeat with thisFile in (selection as alias list)

set the_text to the_text & (read thisFile) & return & "-----------------------------------" & return

end repeat

end tell

return the_text


If desired, this can be:

set the_text to the_text & (read thisFile) & return & name of thisFile & ":" & return


(244775)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Combine txt files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.