More Filters
Paste


The "paste" Filter

We have used grep, cut, and colrm to substract content. Now let's learn to add.

The paste command is used to put two files together. The format for paste is:
     paste file1 file2 ...

Instead of putting file1 on top of file2, file1 and file2 are combined side-by-side.

For example, combining file1 and file2, we would get:
file1
1111 2222 3333 4444
file2
AAAA BBBB CCCC DDDD
paste file1 file2
1111 AAAA 2222 BBBB 3333 CCCC 4444 DDDD
By default, paste inserts a tab between the two columns (which is kinda convenient since cut likes to use tabs also).


Assignment

Create a new script named "swap" that will swap the colomns in a two column file. The two columns should be seperated by a tab.

To test your script you will need to create your own dummy data file with two columns that you can test swapping back and forth.

Here is an example run:
> cat testdata.txt
aaa     bbb
aaaaa   bbbbb
aaaaaaa bbbbbbb

> swap testdata.txt

> cat testdata.txt
bbb     aaa
bbbbb   aaaaa
bbbbbbb aaaaaaa

> swap testdata.txt

> cat testdata.txt
aaa     bbb
aaaaa   bbbbb
aaaaaaa bbbbbbb

This assignment will be kinda tricky. For example, you have to figure out where to keep the first and second columns until you are ready to recombine them.

Note that your script should have NO side-effects.