7. paste

The paste command is similar to the cat command; it merges lines together in a file. Let's create a new file with the following contents:

sample2.txt
The
quick
brown
fox

Let's combine all these lines into one line:

paste -s sample2.txt

The default delimiter for paste is TAB, so now there is one line with TABs separating each word.

Let's change this delimiter (-d) to something a little more readable:

paste -d ' ' -s sample2.txt

Now everything should be on one line delimited by spaces.

Sign in to save your learning progress

Sign in

Exercises

Practice makes perfect! Here are some hands-on labs to reinforce your understanding of text processing and data manipulation in Linux:

  1. Simple Text Processing - Learn to use powerful commands like tr, col, join, and paste to manipulate and analyze text data efficiently.
  2. Data Stream Redirection - Learn the art of Linux stream redirection and how to manipulate standard input, output, and error streams, which is fundamental to understanding how commands like paste operate.
  3. Sequence Control and Pipeline - Learn to control command execution sequences and utilize pipelines, enhancing your ability to combine paste with other commands for complex data tasks.

These labs will help you apply the concepts in real scenarios and build confidence with text processing and data handling in Linux.

Quiz

What flag do you use with `paste` to make everything go on one line?