3. paste
The paste
command does the opposite of cut
. Rather than extracting
a column of text from a file, it adds one or more columns of text to a
file.
To demonstrate how paste
operates, we will perform some surgery on
our distros.txt
file to produce a chronological list of releases.
-
First let's sort distros by date:
head distros.txt
sort -k 3.7nbr -k 3.1nbr -k 3.4nbr \
distros.txt > distros-by-date.txthead distros-by-date.txt
-
Next, let's use
cut
to extract the first two fields/columns from the file (the distro name and version):cut -f 1,2 distros-by-date.txt > distros-versions.txt
head distros-versions.txt
Let's also extract the release dates:
cut -f 3 distros-by-date.txt > distros-dates.txt
head distros-dates.txt
-
To complete the process, let's use
paste
to put the column of dates ahead of distro names and versions, thus creating a chronological list:paste distros-dates.txt distros-versions.txt \
> distros-chronological.txthead distros-chronological.txt
Download lesson07/part3.cast
Loading asciinema cast...