perl help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mohan705
    New Member
    • Sep 2008
    • 2

    perl help

    Hi
    I want to search for columns start_dt and end_dt in all my tables ,wrote shell sript to find the list of tables .I am new to perl want to do it same in perl.Any help it would be appericiated

    [code=perl]
    for name in `cat list.txt`
    do
    tabname=`awk /CREATE TABLE /{table=$2; start=0; }
    /START_DT/ { start++ }
    /END_DT/ && start { print table }' "$name.sql" `
    echo $tabname
    done
    [/code]
    Thanks,
    MR
    Last edited by eWish; Sep 20 '08, 02:40 PM. Reason: Added code tags
  • mohan705
    New Member
    • Sep 2008
    • 2

    #2
    Hi

    I want to search for columns start_dt and end_dt in all my tables ,wrote shell sript to find the list of tables .I am new to perl want to do it same in perl.Any help it would be appericiated.

    Code:
    for name in `cat list.txt`
    do 
    tabname=`awk  /CREATE TABLE /{table=$2; start=0; }
     /START_DT/ { start++ }
     /END_DT/ && start  { print table }'  "$name.sql"`
    echo $tabname
    done
    Thanks,
    MR
    Last edited by eWish; Sep 20 '08, 02:39 PM. Reason: Fixed code tags

    Comment

    • numberwhun
      Recognized Expert Moderator Specialist
      • May 2007
      • 3467

      #3
      First, you need to please learn to use code tags. eWish has corrected them for you, but you need to really use them when posting code in the forums. The example is in the Reply Guidelines to the right of your reply window.

      As for you code, that is not the proper way to access a database. You really want to use the DBI module from CPAN as it is the proper way to access a database.

      Regards,

      Jeff

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        Originally posted by numberwhun
        First, you need to please learn to use code tags. eWish has corrected them for you, but you need to really use them when posting code in the forums. The example is in the Reply Guidelines to the right of your reply window.

        As for you code, that is not the proper way to access a database. You really want to use the DBI module from CPAN as it is the proper way to access a database.

        Regards,

        Jeff
        He appears to be searching through a text file, but my awk is not good enough to read the code.

        I suggest he posts on www.unix.com in the Shell Scripting Forum top get an answer to this question.

        Comment

        • numberwhun
          Recognized Expert Moderator Specialist
          • May 2007
          • 3467

          #5
          Originally posted by KevinADC
          He appears to be searching through a text file, but my awk is not good enough to read the code.

          I suggest he posts on www.unix.com in the Shell Scripting Forum top get an answer to this question.
          The file he is searching through is the exported data from a table. When you export it to a file, it has all the statements inside of the file to re-create the table when "imported". (including the CREATE TABLE statement he has referenced.

          My suggestion to him is, if he is going to seach a table for data, that he do it on the actual table in the database, instead of the back up file. Off hand, I don't remember the format of the backup file for the data portion.

          Regards,

          Jeff

          Comment

          Working...