Comparison of 2 files and generating the output based on comparison

Discussion in 'Perl Misc' started by Deepu, Feb 7, 2011.

  1. Deepu

    Deepu Guest

    Hi All,

    I need some help for a scenario explained below.

    File A has content as below:

    -from logic.blocka.reg* -to logic.blockb.temp_reg*
    -from logic.blockb.reg* -to logic.blockc.*reg*
    -from logic.blockc.*reg* -to logic.blockb.reg*

    File B has content as below:

    tb/device/logic/blocka/reg_0/Q
    tb/device/logic/blocka/reg_1/Q
    tb/device/logic/blocka/reg_2/Q
    tb/device/logic/blocka/reg_3/Q
    tb/device/logic/blockb/reg_0/Q
    tb/device/logic/blockb/reg_1/Q
    tb/device/logic/blockc/ff_reg_0/Q
    tb/device/logic/blockc/ff_reg_1/Q

    tb/device/logic/blockb/temp_reg_0/D
    tb/device/logic/blockb/temp_reg_1/D
    tb/device/logic/blockb/temp_reg_2/D
    tb/device/logic/blockb/temp_reg_3/D
    tb/device/logic/blockc/ff1_reg_0/D
    tb/device/logic/blockc/ff1_reg_1/D
    tb/device/logic/blockb/reg_0/D
    tb/device/logic/blockb/reg_1/D


    Now i need to look into File A and for 1st line for example

    "-from logic.blocka.reg* -to logic.blockb.temp_reg*"

    Look into File B for the path name after 'from' and 'to' and then
    prepare an output as below:


    always @ (tb.device.logic.blocka.reg_0.Q)
    begin
    @ (tb.device.logic.blockb.temp_reg_0.D);
    end

    always @ (tb.device.logic.blocka.reg_1.Q)
    begin
    @ (tb.device.logic.blockb.temp_reg_0.D);
    end

    always @ (tb.device.logic.blocka.reg_2.Q)
    begin
    @ (tb.device.logic.blockb.temp_reg_0.D);
    end

    always @ (tb.device.logic.blocka.reg_3.Q)
    begin
    @ (tb.device.logic.blockb.temp_reg_0.D);
    end


    Thanks for your time..
     
    Deepu, Feb 7, 2011
    #1
    1. Advertising

  2. Deepu

    ccc31807 Guest

    On Feb 7, 2:27 am, Deepu <> wrote:
    > I need some help for a scenario explained below.


    This is a typical data munging task. Pseudo code for your script is as
    follows, at least as a first step:

    open file A
    for each line in file A
    - split the line
    - stuff the values into a suitable data structure (perhaps %A)
    close file A

    open file B
    for each line in file B
    - split the line
    - stuff the values into a suitable data structure (perhaps %B)
    close file B

    iterate through %A
    - if there is a match with an element of %B, print

    From the appearance of your data, you could probably throw away the
    first three directories, tb, device, and logic. It strikes me that (as
    a first try) you might want to replace the delimiter in each line to a
    common delimiter, perhaps a colon, save the whole thing as a string,
    and then use a regular expression to match against the string.

    From there, you can optimize, perhaps by just saving the values in the
    first file as an array of strings, and directly match the values in
    the second file without using a second data structure. This depends on
    the nature of your data, and if your data is sorted in some kind of
    way, the task become much easier.

    Your question isn't a Perl question as such, but more of a general
    question applicable to whatever language you would want to use,
    although Perl can certainly handle this task with ease and speed.

    CC.


    >
    > File A has content as below:
    >
    > -from logic.blocka.reg*  -to logic.blockb.temp_reg*
    > -from logic.blockb.reg*  -to logic.blockc.*reg*
    > -from logic.blockc.*reg* -to logic.blockb.reg*
    >
    > File B has content as below:
    >
    > tb/device/logic/blocka/reg_0/Q
    > tb/device/logic/blocka/reg_1/Q
    > tb/device/logic/blocka/reg_2/Q
    > tb/device/logic/blocka/reg_3/Q
    > tb/device/logic/blockb/reg_0/Q
    > tb/device/logic/blockb/reg_1/Q
    > tb/device/logic/blockc/ff_reg_0/Q
    > tb/device/logic/blockc/ff_reg_1/Q
    >
    > tb/device/logic/blockb/temp_reg_0/D
    > tb/device/logic/blockb/temp_reg_1/D
    > tb/device/logic/blockb/temp_reg_2/D
    > tb/device/logic/blockb/temp_reg_3/D
    > tb/device/logic/blockc/ff1_reg_0/D
    > tb/device/logic/blockc/ff1_reg_1/D
    > tb/device/logic/blockb/reg_0/D
    > tb/device/logic/blockb/reg_1/D
    >
    > Now i need to look into File A and for 1st line for example
    >
    > "-from logic.blocka.reg*  -to logic.blockb.temp_reg*"
    >
    > Look into File B for the path name after 'from' and 'to' and then
    > prepare an output as below:
    >
    > always @ (tb.device.logic.blocka.reg_0.Q)
    >   begin
    >     @ (tb.device.logic.blockb.temp_reg_0.D);
    >   end
    >
    > always @ (tb.device.logic.blocka.reg_1.Q)
    >   begin
    >     @ (tb.device.logic.blockb.temp_reg_0.D);
    >   end
    >
    > always @ (tb.device.logic.blocka.reg_2.Q)
    >   begin
    >     @ (tb.device.logic.blockb.temp_reg_0.D);
    >   end
    >
    > always @ (tb.device.logic.blocka.reg_3.Q)
    >   begin
    >     @ (tb.device.logic.blockb.temp_reg_0.D);
    >   end
    >
    > Thanks for your time..
     
    ccc31807, Feb 7, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave
    Replies:
    1
    Views:
    446
    =?Utf-8?B?SGVybWl0IERhdmU=?=
    Jan 30, 2006
  2. JR
    Replies:
    2
    Views:
    405
    Alex Hunsley
    Mar 12, 2006
  3. Dag Sunde
    Replies:
    7
    Views:
    1,316
    Dimitre Novatchev
    Mar 10, 2007
  4. Nathan Sokalski
    Replies:
    1
    Views:
    524
    Nathan Sokalski
    May 15, 2007
  5. Replies:
    4
    Views:
    398
    Richard Harter
    Aug 20, 2007
Loading...

Share This Page