Find the answer to your Linux question:
Results 1 to 1 of 1
i have a problem in finding block of identical strings...i solved the problem in finding consecutive identical words and now i want to expand the code in order to find ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2011
    Posts
    3

    finding and removing block of identical strings


    i have a problem in finding block of identical strings...i solved the problem in finding consecutive identical words and now i want to expand the code in order to find and remove consecutive identical block of strings...
    for example the awk code removing consecutive identical word is:
    Code:
    #!/usr/bin/awk -f
    BEGIN{
    RS="[[:space:]]+";
    ORS=""
    }
    match($0,/^([[:punct:]]*)([^[:punct:]]+)([[:punct:]]*)$/,f){
    if(x != f[2])
    {
    print y$0;z = FNR
    }
    x = f[2];
    y = RT
    }
    END{
    if(z != FNR)
    print f[3]"\n"
    }
    input:
    "ana are mere mere
    mere si portocale
    ion are prune prune."

    output:
    "ana are mere si portocale
    ion are prune."

    and now i want to expand the code to do the following:
    input:
    "ana are ana are mere
    ion are prune ion are prune"

    output:
    "ana are mere
    ion are prune"

    thanks
    Last edited by cocostaec; 05-16-2011 at 02:58 PM.

Posting Permissions

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