How is the paste command used in Linux?
The paste command is used to combine the contents of multiple files line by line, merging the content of two or more files into one file with each file’s content taking up a column. The basic syntax is:
paste [OPTION]... [FILE]...
Common options include:
- Specify the delimiter for merging, the default is the Tab key.
- -s: Merge the file into one line output line by line.
For instance, merge the contents of file1.txt and file2.txt line by line and output them to the file output.txt.
paste file1.txt file2.txt > output.txt
To set the delimiter as a comma, you can use the -d option.
paste -d ',' file1.txt file2.txt > output.txt
To merge the lines of a file into one line for output, you can use the -s option.
paste -s file1.txt file2.txt > output.txt