- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to merge lines of files in the Linux system?
To merge lines of files, we use the paste command in the Linux system.
The paste command is used to combine files horizontally by outputting lines consisting of the sequentially corresponding lines from each FILE, separated by TABs to the standard output. When it has completed its operating for the last file, paste will output newline character and move on to the next line.
The general syntax of the paste command is as follows −
paste [OPTION]... [FILE]...
Note – with no FILE the paste command read input from standard input.
Brief description of options available in the paste command.
|Sr.No.||Option & Description|
Reuse characters from LIST instead of TABs
Paste one file at a time instead of in parallel
Line delimiter is NULL, not newline
Displays a help message and then exits.
It gives info about the version and then exits.
To merge the files parallelly, we use the paste command as shown below.
First, we need to create two files to merge simultaneously.
$ cat >text1.txt EMP_ID EMP_NAME 001 GAURAV 002 SID $ cat >text2.txt EMP_AGE 22 23 $ paste text1.txt text2.txt EMP_ID EMP_NAME EMP_AGE 001 GAURAV 22 002 SID 23
Here, we will use the above files and save output in another file instead of standard output using the paste command in the Linux system as shown below.
$ paste text1.txt text2.txt >text.txt
To merge the files parallelly with delimiter, we use the -d option with the paste command as shown below.
$ paste -d ‘|’ text1.txt text2.txt EMP_ID EMP_NAME |EMP_AGE 001 GAURAV |22 002 SID |23
To merges the files in a sequential manner, we use the -s option with the paste command as shown below.
$ paste -s text1.txt text2.txt
To check more information about the paste command, we use the --help option with the paste command in the Linux operating system as shown below.
$ paste --help
To check version information of the paste command, we use the --version option with the paste command in the Linux operating system as shown below.
$ paste --version
- How to sort lines of text files in Linux?\n
- How to join lines of two files on a common field in Linux?
- How to remove sections from each line of files in the Linux system?\n
- How to compare two sorted files line by line in the Linux system?
- How to remove files and directories in the Linux operating system using the terminal?\n
- How to create links between files in the Linux?
- How to flushes file system buffers in the Linux operating system?
- How to display the first part of the file in the Linux system?
- How to converts tabs to spaces in the Linux system?
- How to move jobs to the background in the Linux system?
- How to format contents of a text file in the Linux system?
- How to search contents of multiple pdf files on Linux?
- Java program to merge contents of all the files in a directory
- How to retrieve a specific number of lines from files in PowerShell?
- How to display the last part of the file in the Linux system?\n