You're viewing a comment by Gaurav and its responses.

Gaurav Permalink
May 18, 2012, 09:23

thnx peter for the explanation..... one more thing i would like to ask suppose i have 2 files in the first file i have these variables like aa, ab, ac and so on upto bx and in the second file i am having lines like
this is first line
this is second line.
now i want to combine these files and wanna get output like this
aa=this is first line
ab=this is second line
..... and so on upto
bx=this is 50th line.

many thanx in advance .....

Comment Responses

May 18, 2012, 13:01

Very easy mate, use the paste unix command. Like this:

paste -d= file1 file2

Here is my example. I have this in file1:

a
b
c
d
e
f

And I have this in file2:

1
2
3
4
5
6

Now when I run paste -d= file1 file2, I get:

a=1
b=2
c=3
d=4
e=5
f=6
Gaurav Permalink
May 18, 2012, 15:12

thnx peter :)

Anirudh Permalink
February 04, 2016, 10:11

You could emulate the Unix's "paste" command in sed as shown
(assuming both files of equal length and no empty lines)

echo '.' | { cat input_f1 - input_f2; } |
sed -ne '
   1{
      :file1
         H;1h;n
         /^[.]$/d
      bfile1
   }
   /\n/{h;n;}
   G
   s/\n/&&/2
   s/\(.*\n\)\(.*\)\n\n/\2=\1/
   P
   /\n.*\n/D
   s/.*\n//
   N;s/\n/=/p
'

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "rocket_95": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.