Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Find and sort by first column value

$
0
0
Hi,
I have two text files
file 1 with N lines

Code:

AAAAA        2.092290E-12
BBBBB        1.727740E-07
CCCCC        9.608710E-17
DDDDD        0.000000E+00
EEEEE        0.000000E+00
FFFFF        0.000000E+00
GGGGG        0.000000E+00
HHHHH        0.000000E+00
IIIII        3.300320E-04
...

The text in the first column is unique for each row and alphabetically sorted A->Z.

file 2 with M lines (M>=N)

Code:

AAAAA        text1        5.07822E-02
DDDDD        text2        8.45965E-03
CCCCC        text3        4.33704E-03
BBBBB        text4        0.00000E+00
EEEEE        text3        5.05173E+00
GGGGG        text4        2.83088E-03
...

The text in the first column is unique for each row.

What I would like to obtain is file 3 containing only the rows of file 2 with an "column1 entry" in file 1 and sorted as they appear in file 1.
If the entry is not present I would like to have a warning message (as below).

file 3 with N lines

Code:

AAAAA        text1        5.07822E-02
BBBBB        text4        0.00000E+00
CCCCC        text3        4.33704E-03
DDDDD        text2        8.45965E-03
EEEEE        text3        5.05173E+00
FFFFF        NOT        FOUND
...

Do you have any suggestion?

Many thanks,

Viewing all articles
Browse latest Browse all 16232

Trending Articles