Linux Tutorial on Elango Notes
This linux tutorial provides 5 practical examples of paste command in linux / unix OS. This includes files merging horizontally, sequentially, displaying file contents, etc,…
Paste Command
- This command is mainly used to merge the file contents horizontally
- This command is also used to display the single file contents.
1. Files Merging Horizontally
- Be default, the paste command will be used to merge the two or more number of files horizontally (parallelly) with tab delimiter
Syntax
paste file1 file2 … file n
Example
- Here files like f1.txt, f2.txt and f3.txt are merged horizontally with tab delimiter by default using paste command.
2. Files Merging Horizontally with delimiter option
- Be default, files are merged horizontally (parallelly) with tab delimiter
- If you want to change the tab delimiter, then you have to use the special option -d with new delimiter like space, |, etc
- The delimiter should be given inside the single quote or double quotes.
Syntax
paste -d “ ”file1 file2 … file n
Example
3. Files Merging Horizontally Sequentially
- By default, files are merged horizontally (parallelly)
- If you want to merge files sequentially (one by one) then we need to use the special option -s (serial)
Note
- In this option, the whole file contents will be read line by line and merge them into single line where each line is separated by tab
- Finally all lines of files are merged sequentially separated by newline
Syntax
paste -s “ ”file1 file2 … file n
Example
4. Displaying File Contents using Paste
- Like cat command, paste command will also display the file contents
- If paste command will take only one argument as file input then will display the file contents instead of merging.
Syntax
paste filename
Example
5. Reading and Displaying Data in Paste Command
- If paste command is used without any option, then it will read the data from standard input and display them immediately to standard output until stop using ctrl+c or ctrl+z.
Syntax
paste
Example
1 thought on “How to use Paste Command in Linux [5 Examples]”
Comments are closed.