The ‘paste’ command will merge multiple files line by line, and you can declare a delimiter between the files’ contents.

This would be really useful for, say, creating a CSV using the contents of multiple files. You could run the following command and instantly create a CSV.

$ paste -d',' column1.txt column2.txt

Another use I have found recently is to help generate large SQL create table statements. For instance, say that I have two files. File ‘file_a.txt’ has the following contents (SQL types).

INT
INT
STRING
DOUBLE
STRING
STRING

File ‘file_b.txt’ has the corresponding SQL column names.

width
length
name
cost
comment1
comment2

I can form a create table SQL statement in Bash very quickly using paste:

$ echo -e "CREATE TABLE my_table (\n$(paste -d' ' file_a.txt file_b.txt))"
CREATE TABLE my_table (
INT width
INT length
STRING name
DOUBLE cost
STRING comment1
STRING comment2)
Posted in Bash
Share this post, let the world know

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">