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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

more questions regarding spliting a file by paragraphs

Status
Not open for further replies.

orangegal

Technical User
Oct 12, 2005
15
US
okok, here's what i did, but it only prints out the first line of the document, i also tried "\n\n", it does the same thing, this one little problem is killing me. thanks for everyone's help

==================================================
$file = 'test';
open FILE, $file;
$file1=<FILE>;
chomp;
@paras=split /^$/, $file1;
foreach(@paras) {
print "$_";
print "="x40;
}
===================================================
 
Posting some data would probably make it easier.
 
thanks, rharsh
for instance, here's my dataset, if i want to seperate these two paragraph, how would i do it?

actually, my current goal is to sort the data, for instance, the first line is the "alert name", then "classification" then "priortity"... etc
==================================================
[**] [1:483:5] ICMP PING CyberKit 2.2 Windows [**]
[Classification: Misc activity] [Priority: 3]
09/19-13:35:41.644975 0:3:6C:A8:44:0 -> 0:11:11:5A:F0:9C type:0x800 len:0x4A
***.***.**.** -> ***.**.***.** ICMP TTL:127 TOS:0x0 ID:24623 IpLen:20 DgmLen:60
Type:8 Code:0 ID:512 Seq:38080 ECHO
[Xref => ]

[**] [1:1411:10] SNMP public access udp [**]
[Classification: Attempted Information Leak] [Priority: 2]
09/19-13:37:16.503268 0:F:3D:1:2B:4A -> 0:4:0:5D:FD:35 type:0x800 len:0x78
***.***.**.** -> ***.**.***.** UDP TTL:127 TOS:0x0 ID:9446 IpLen:20 DgmLen:106
Len: 78
[Xref => ][Xref => ][Xref => ][Xref => ][Xref => ][Xref => ]
 
This should read in one paragraph at a time:
Code:
{local $/ = "\n\n";
 my $paragraph;
 while ($paragraph = <DATA>) {
    chomp $paragraph;
    print $paragraph, "\n";
    print '-' x 40, "\n";
 }
}

__DATA__
[**] [1:483:5] ICMP PING CyberKit 2.2 Windows [**]
[Classification: Misc activity] [Priority: 3]
09/19-13:35:41.644975 0:3:6C:A8:44:0 -> 0:11:11:5A:F0:9C type:0x800 len:0x4A
***.***.**.** -> ***.**.***.** ICMP TTL:127 TOS:0x0 ID:24623 IpLen:20 DgmLen:60
Type:8  Code:0  ID:512   Seq:38080  ECHO
[Xref => [URL unfurl="true"]http://www.whitehats.com/info/IDS154[/URL]]

[**] [1:1411:10] SNMP public access udp [**]
[Classification: Attempted Information Leak] [Priority: 2]
09/19-13:37:16.503268 0:F:3D:1:2B:4A -> 0:4:0:5D:FD:35 type:0x800 len:0x78
***.***.**.** -> ***.**.***.** UDP TTL:127 TOS:0x0 ID:9446 IpLen:20 DgmLen:106
Len: 78
[Xref => [URL unfurl="true"]http://cve.mitre.org/cgi-bin/cvename.cgi?name=2002-0013[/URL]][Xref => [URL unfurl="true"]http://cve.mitre.org/cgi-bin/cvename.cgi?name=2002-0012[/URL]][Xref => [URL unfurl="true"]http://cve.mitre.org/cgi-bin/cvename.cgi?name=1999-0517[/URL]][Xref => [URL unfurl="true"]http://www.securityfocus.com/bid/4089[/URL]][Xref => [URL unfurl="true"]http://www.securityfocus.com/bid/4088[/URL]][Xref => [URL unfurl="true"]http://www.securityfocus.com/bid/2112[/URL]]
 
thank you so much rharsh!!! it seems that what you did is the same as mine, but it made the whole thing work!, i can't be happier
 
Using Paul's code from your other post, you forgot a line. Try adding
Code:
$/=undef;
before
Code:
$file1=<FILE>;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top