Linux – How to insert a custom string into the result of the Linux paste command

How to insert a custom string into the result of the Linux paste command… here is a solution to the problem.

How to insert a custom string into the result of the Linux paste command

I know that the Linux command paste can be used to merge two lines in two files. My question is how to add some other strings to it?

For example I have 2 files:

[root@localhost ~]# cat c1
aaaa
bbbbbbbbbbbbb
[root@localhost ~]# cat c2
11111111
222222222222
[root@localhost ~]# 
[root@localhost ~]# paste c1 c2
aaaa    11111111
bbbbbbbbbbbbb   222222222222
[root@localhost ~]# 

How to insert text between them, for example, how to get the following result?

var aaaa = some_function(11111111);
var bbbbbbbbbbbbb = some_function(222222222222);

Can this be achieved with the paste command? Thank you.

Solution

Maybe there’s a way to do it with paste, but it’s certainly easy to do with awk :

paste c1 c2 | awk '{ printf("var %s = some_function(%s);\n", $1, $2); }'

Related Problems and Solutions