Join Lines of Text File Together
This page answers questions like these:
- How to join lines of a text file together and put a separator between each line?
- How to join lines of a text file together with a separator?
- How to join lines of a text file together without a separator?
Related Links:
Count Occurrences of a Hexadecimal Sequence in a File
Count Occurrences of a String in a File
Find Positions of a Hexadecimal Sequence in a File
Output Lines of a File in Reverse Order
Output the Lines Between Two Matching Lines
Sed Cannot Rename Temporary File Permission Denied
Join Lines of Text File Together without a Separator:
tr -d '\n\r' < FILE1 > FILE2
- Get all lines of text file FILE1, join them together, and write the result to file FILE2.
- Pros: Fast. Works on text files from Unix, Linux, DOS, Windows, and Mac.
- Cons: tr cannot do in-file replacement, i.e. it requires the output file FILE2 to be different from the input file FILE1.
Join Lines of Text File Together with a Separator:
sed -i ':a;N;s/\n/SEPARATOR/;ba' FILE
- Join all lines of a text file FILE together with string SEPARATOR between each line.
- Pros: The string SEPARATOR can be of any length. The -i option to sed does in-file replacement. You can also write to stdout or another file by removing the -i option.
- Cons: Slow on large files.
Related Links:
Count Occurrences of a Hexadecimal Sequence in a File
Count Occurrences of a String in a File
Find Positions of a Hexadecimal Sequence in a File
Output Lines of a File in Reverse Order
Output the Lines Between Two Matching Lines
Sed Cannot Rename Temporary File Permission Denied
Home > Linux / Unix > Join Lines of Text File Together
Tags: join lines, join, lines, text file, text, shell command, shell, command, linux, unix, solaris, bsd, aix
Copyright © HelpDoco.com
file-join-lines.txt
Linux-Unix/join-lines-of-a-text-file-together.htm
2