< Previous | Contents | Next >
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. It does this by reading multiple files and combining the fields found in each file into a single stream on standard output. Like cut, paste accepts multiple file arguments and/or standard input. To demonstrate how paste operates, we will perform some surgery on our distros.txt file to pro- duce a chronological list of releases.
From our earlier work with sort, we will first produce a list of distros sorted by date and store the result in a file called distros-by-date.txt:
[me@linuxbox ~]$ sort -k 3.7nbr -k 3.1nbr -k 3.4nbr distros.txt > dis tros-by-date.txt
[me@linuxbox ~]$ sort -k 3.7nbr -k 3.1nbr -k 3.4nbr distros.txt > dis tros-by-date.txt
Next, we will use cut to extract the first two fields from the file (the distro name and version), and store that result in a file named distro-versions.txt:
[me@linuxbox ~]$ cut -f 1,2 distros-by-date.txt > distros-versions.t xt
[me@linuxbox ~]$ head distros-versions.txt
Fedora | 10 |
Ubuntu | 8.10 |
SUSE | 11.0 |
Fedora | 9 |
Ubuntu | 8.04 |
Fedora | 8 |
Ubuntu | 7.10 |
SUSE | 10.3 |
Fedora | 7 |
Ubuntu | 7.04 |
The final piece of preparation is to extract the release dates and store them a file named
distro-dates.txt:
[me@linuxbox ~]$ cut -f 3 distros-by-date.txt > distros-dates.txt
[me@linuxbox ~]$ head distros-dates.txt
11/25/2008
10/30/2008
06/19/2008
05/13/2008
04/24/2008
11/08/2007
10/18/2007
10/04/2007
05/31/2007
04/19/2007
[me@linuxbox ~]$ cut -f 3 distros-by-date.txt > distros-dates.txt
[me@linuxbox ~]$ head distros-dates.txt
11/25/2008
10/30/2008
06/19/2008
05/13/2008
04/24/2008
11/08/2007
10/18/2007
10/04/2007
05/31/2007
04/19/2007
We now have the parts we need. To complete the process, use paste to put the column of dates ahead of the distro names and versions, thus creating a chronological list. This is done simply by using paste and ordering its arguments in the desired arrangement:
[me@linuxbox | ~]$ paste | distros-dates.txt distros-versions.txt |
11/25/2008 | Fedora | 10 |
10/30/2008 | Ubuntu | 8.10 |
06/19/2008 | SUSE | 11.0 |
05/13/2008 | Fedora | 9 |
04/24/2008 | Ubuntu | 8.04 |
11/08/2007 | Fedora | 8 |
10/18/2007 | Ubuntu | 7.10 |
10/04/2007 | SUSE | 10.3 |
05/31/2007 | Fedora | 7 |
04/19/2007 | Ubuntu | 7.04 |
12/07/2006 | SUSE | 10.2 |
10/26/2006 | Ubuntu | 6.10 |
10/24/2006 | Fedora | 6 |
06/01/2006 | Ubuntu | 6.06 |
05/11/2006 | SUSE | 10.1 |
03/20/2006 | Fedora | 5 |