The paste command

Ensure that you have the files telnum.txt and columns.txt in your working directory.

We've done the cut command, there has to be an equivalent command called paste?

paste is a way of pasting two files together provided we have exactly the same number of lines in every file - if not, paste will paste from the top of the file.

How do we check how many lines we have in a file?

wc -l columns.txt telnum.txt
            

Since there are an equal number of lines, we're going to use the paste command to paste the two files together, and save the result into a new file called contact.txt by redirecting the output.

	
paste columns.txt telnum.txt > contact.txt
            

The paste command is not quite as useful as cut, but it can be used relatively effectively and we'll work with it in some detail later on. Paste does take delimiters too. So for example, we could rewrite the command with:

paste -d';' columns.txt telnum.txt > contact.txt
            

This would paste the two files together using a delimiter of semicolon. It might be worth giving that a bash just to see what the output is.

Now, in my telnum.txt file I have spaces, round brackets and dashes and all sorts of other troublesome characters that might cause us problems later. I'm going to replace all 's('s and 's)'s with nothing, and all spaces with a dash. Thus if I had

(021) 654-1234
            

I want to replace it with

021-654-1234
            

We do this with the following search and replace command:

sed 's/(//g;s/)//g;s/ /-/g' telnum.txt > modtelnum.txt
            

Then produce an updated contact.txt where all the telephone numbers have been standardised.

paste -d';' columns.txt modtelnum.txt > contact.txt
            

If I use the -d';' delimitor, only two letters from the last two names are added, not any other.

If I use it without the -d';' delim. Most of the names are recreated in the new file, though the longer ones are truncated.

Now, all spurious characters have been removed from the file contact.txt.

We are still going to cover the following three commands: uniq, sort and grep. I've left grep right 'till last because it's a very slow "Swiss army knife". Which is why I suggest you know how to get the information you want without using grep. grep should be used as a last resort, because it uses so much system resources.