I have two files File-1 and File-2 with data in columns. I want to create another file and copy the data of the first column of File-2 corresponding to the data to file-1 in row wise as given below.


A  P
B  Q
C  R


5.4  9.0
7.4  11.5
9.4  15.7


A=5.4, B=7.4, C=9.4

I want my output in a row form like above only for first column data.
I appreciate your help!!
Thanks in advance!!!

2 Answers 2


Note that a "join" (mentioned in the question title) is a specific operation where one data set is used to extract data from another data set (a relational join operation). This may be done with the join utility (or with a short awk command).

What you want to do is a data extraction and a merge. This is well explained by you in the question text.

Assuming you have the bash shell, the contents of the first column of each file can be extracted using cut, and then merged with = as a delimiter using paste:

$ paste -d '=' <(cut -d ' ' -f 1 File-1) <(cut -d ' ' -f 1 File-2)

Each <(...) (process substitution) will be replaced with the name of a temporary file from where the output of the cut command inside the substitution will be available for paste to read.

You can then merge this into a single comma-delimited line like so:

$ paste -d '=' <(cut -d ' ' -f 1 File-1) <(cut -d ' ' -f 1 File-2) | paste -d ',' -s -

If you require spaces after each comma, sed may be used:

$ paste -d '=' <(cut -d ' ' -f 1 File-1) <(cut -d ' ' -f 1 File-2) | paste -d ',' -s - | sed 's/,/, /g'
A=5.4, B=7.4, C=9.4

Note that I have assumed that the empty lines in the question is not actually part of the data files. You may want to pre-process the data with sed '/^[[:blank:]]*$/d', which would delete any lines that are empty or that only contains spaces and/or tabs.

See also the manual for cut and paste (man cut and man paste).

$ paste file1 file2 | awk '{printf "%s%s=%s", sep, $1, $3; sep=", "} END{print ""}'
A=5.4, B=7.4, C=9.4
  • 1
    wow great!!! thanks @Ed Morton
    – sai
    Commented Jan 13, 2021 at 6:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .