×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Extracting Data from a CSV file

Extracting Data from a CSV file

Extracting Data from a CSV file

(OP)
Greetings,

I'm new at PERL but I have scripting experience in a proprietery language (very c+ like but less type strict).  I need a quick turn-around for the BOSS and can't take the time to dive deep into PERL the way I'd like to, so I'm turning to everyone for some help.   PLEASE.

PERL is up and running on NT just fine.  

I have a CSV file in rows that has been extracted from the Novell NDS.  Below is a sample of that data.  I want the results from the "Login Script" portion only if it has a #Capture in the value.

------------------------------------------------------------
"User Name","Object Container Name (DN)","Login Script Contents"

"Davismic","Anywhere.ABCDEF","#CAPTURE L=2 Q=.COL2007Q1.ABCDEF NB NFF"
"Dolced","Anywhere.ABCDEF","#CAPTURE L=2 Q=.COL2007Q1.ABCDEF NB NFF"
"Kaysert","Anywhere.ABCDEF","IF NETWORK_ADDRESS = "D4CFF853" THEN GOTO STOP"
"Kaysert","Anywhere.ABCDEF","IF P_STATION<="00000000FFFF" THEN GOTO STOP"
------------------------------------------------------------
I've seen these files sizes to be several MB.

GOAL:
have output that has
"User Name" , "Login Script" if it has a #capture in the value.

My first thoughts were to try to match on the "<line feed>" string.  I know that it is an OD OA in hex but can I use that in PERL?

Any direction is greatly. . . no GREATLY appreciated.


Thanks,
Stel

RE: Extracting Data from a CSV file


#!perl -w
# open an output file.
open(OPF, ">junk.log") or die "Failed to open output file, $!\n";

# open the log file for reading - your csv file.
open(IPF,"<c:/temp/input.txt") or die "Failed to open csv file, $!\n";

# while info come from the IPF handle...
while ($line = <IPF>)
{
$user = ';
$script = ';
# if the line contains the string 'CAPTURE'
if ($line =~ /CAPTURE/)
    {
    # split the parts of the line into an array.
    @parts = split(/","/,$line);
    
    # throw away quotes - a little simple pattern matching
    $user = $parts[0]; # dereference array element
    $user =~ s/"//g;   # replace " with null
    
    $script = $parts[2];    
    $script =~ s/"//g;
    
    # print first and third array elements to output file handle
    print "USER - $user, LOGIN SCRIPT - $script";
    print OPF "USER - $user, LOGIN SCRIPT - $script";
    }
}
close IPF;
close OPF;


This is a little tedious....could be more concise.  But, I left it exploded, so to speak to make the process steps more obvious.   Admittedly, the output may need a little cleaning up, but, hopefully, this gives you the chunks you need to get where you need to go....  ' Hope this helps...




keep the rudder amid ship and beware the odd typo

RE: Extracting Data from a CSV file

(OP)
This worked great!!!  You were a big help.  

Thanks.
Stel

RE: Extracting Data from a CSV file

(OP)
This really REALLY helped me today.  I was able to bring a solution to the table.  No, I didn't take the credit for writing the script, but I did take credit for being able to find a solution to the problem.  I can't thank you enough.  The only way I know how is to keep checking the NT forum and offer my expertice there.  That's what I live and breath 40+ a week.

Thanks again,

Stel

RE: Extracting Data from a CSV file

Glad to help.  Thanks for the thanks and the star;^)




keep the rudder amid ship and beware the odd typo

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close