Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    If 1th col of both file same, export line with max str of 2nd column


    please help to write a awk command-line programs to achieve the following functions: Thank in advance.

    Requeset Description:
    compare two files f1 and f2, export to file f3:
    1 Delete duplicate rows of in file f1 and file f2
    2 If the 1th column of file f1 and file f2 is the same, then export those line with maximum string of 2nd column.
    for example:
    0.1-37 < 0.2-53;
    6.1.4-b.0 < 6.1.5-c.2;
    9.13.2 < 11.5.6;
    18b-16 > 8c-7;
    D15 < F4;
    1.b5_a < 1.b12_d
    4c5.8 < 4c12.8
    d18g < d18j
    3 Rule: For the 2nd column of 2 files:
    > num of 0-9 consecutive occurrences may be different, such as 9.13.2 vs 11.5.6, D15 vs F4
    > The type, order, num of other characters (such as '.' '_' '-' 'A-Z' 'a-Z') except 0-9 is the same.
    like 6.1.4-b.0 vs 6.1.5-c.2, 1.b5_a vs 1.b12_d, D15 vs F4 ....
    > if find the 1st large string after comparison, then stop comparing the 2nd column, and output this line of those file,
    such as 'IO 1.b5_a' of f1, 'IO 1.b12_d' of f2, will output 'IO 1.b12_d'

    4 cat f1:
    PK 0.1-37
    Art 6.1.4-b.0
    Fle 9.13.2
    Uni 18b-16
    STD D15
    IO 1.b5_a
    FPG 4c5.8
    SRA d18g
    ....
    ....

    cat f2:
    Uni 8c-7
    IO 1.b12_d
    Art 6.1.5-c.2
    PK 0.2-53
    Fle 11.5.6
    SRA d18j
    STD F4
    FPG 4c12.8
    ....
    ....

    desired file f3:
    Art 6.1.5-c.2
    Fle 11.5.6
    IO 1.b12_d
    PK 0.2-53
    STD F4
    Uni 18b-16
    FPG 4c12.8
    SRA d18j
    ...
    ...

  2. #2
    Linux User
    Join Date
    Jul 2016
    Posts
    443
    Quote Originally Posted by weichanghe2000 View Post
    please help to write a awk command-line programs to achieve the following functions: Thank in advance.

    Requeset Description:
    compare two files f1 and f2, export to file f3:
    1 Delete duplicate rows of in file f1 and file f2
    2 If the 1th column of file f1 and file f2 is the same, then export those line with maximum string of 2nd column.
    for example:
    0.1-37 < 0.2-53;
    6.1.4-b.0 < 6.1.5-c.2;
    9.13.2 < 11.5.6;
    18b-16 > 8c-7;
    D15 < F4;
    1.b5_a < 1.b12_d
    4c5.8 < 4c12.8
    d18g < d18j
    3 Rule: For the 2nd column of 2 files:
    > num of 0-9 consecutive occurrences may be different, such as 9.13.2 vs 11.5.6, D15 vs F4
    > The type, order, num of other characters (such as '.' '_' '-' 'A-Z' 'a-Z') except 0-9 is the same.
    like 6.1.4-b.0 vs 6.1.5-c.2, 1.b5_a vs 1.b12_d, D15 vs F4 ....
    > if find the 1st large string after comparison, then stop comparing the 2nd column, and output this line of those file,
    such as 'IO 1.b5_a' of f1, 'IO 1.b12_d' of f2, will output 'IO 1.b12_d'

    4 cat f1:
    PK 0.1-37
    Art 6.1.4-b.0
    Fle 9.13.2
    Uni 18b-16
    STD D15
    IO 1.b5_a
    FPG 4c5.8
    SRA d18g
    ....
    ....

    cat f2:
    Uni 8c-7
    IO 1.b12_d
    Art 6.1.5-c.2
    PK 0.2-53
    Fle 11.5.6
    SRA d18j
    STD F4
    FPG 4c12.8
    ....
    ....

    desired file f3:
    Art 6.1.5-c.2
    Fle 11.5.6
    IO 1.b12_d
    PK 0.2-53
    STD F4
    Uni 18b-16
    FPG 4c12.8
    SRA d18j
    ...
    ...
    so by 'help" you mean 'someone do my homework for me so i dont have to spam a bunch of linux forums begging for handouts"??? no thanks. if you want help post what you tried already. otherwise do your own homework

  3. #3
    Linux Guru
    Join Date
    Dec 2013
    Posts
    2,747
    -->
    ^ agreed.
    sadly.
    a highly detailed problem description, requirements down to what language needs to be used, yet no larger picture and zero effort shown to actually tackle the problem == homework.

$spacer_open
$spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •