Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing text....

Status
Not open for further replies.

broloc

Programmer
Jun 10, 2002
27
JP
needd help....

i have a problem using to parse the data from the file.
could some one please help me....
i got a text file named 'nmap.txt'with the data:

80/tcp http
23/tcp telnet

what i'm going to do is read the data from the file using regular expression. so my output should be like this:
80/tcp
23/tcp

how can i do that?
could someone please help me because i'm a beginner with this perl
 
This should do it...(ther are many more ways)

open(IN,"$myinput_file") or die "cannot open $myinput_file\n";
open(OUT,">RESULTS") or die "cannot open RESULTS\n";
while(<IN>){chomp;
my $line=$_;
#just in case ther are leading spaces, remove them
$line=~s/^\s+//;
# if you see a blank line skip it
next unless $line;
die &quot;unexpected input $line\n&quot; unless $line=~/(.*)\s+(.*)/;
my $first=$1;
print OUT &quot;$first\n&quot;;}
close(IN);close(OUT);

svar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top