Help in scripting needed

Discussion in 'Programming' started by ngupta, Mar 6, 2009.

  1. #1
    I have a file say File1.Now i need a specific pattern from the lines to be added to the other line.

    File

    red
    blue
    green
    ABC.txt@ABC
    END
    black
    ash
    grey
    purple
    XYZ.txt@XYZ
    orange
    pink
    yellow
    marroon
    PQR.txt@PQR

    Now i want the file to look like this<br>

    #change ABC
    red
    blue
    green
    ABC.txt@ABC
    END
    #change XYZ
    black
    ash
    grey
    purple
    XYZ.txt@XYZ
    END
    #change PQR
    orange
    pink
    yellow
    marroon
    PQR.txt@PQR
    END
     
    ngupta, Mar 6, 2009 IP
  2. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #2
    so, first you would iterate over the list and Inject an End at the end, and after ever regex.match of (/@/), then iterate again, and if the next one in line = END, then, put a # char. then, split on "END", add a # at the beginning from the first of the match and concatenate all back together ;)
     
    ccoonen, Mar 6, 2009 IP