470,618 Members | 1,723 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,618 developers. It's quick & easy.

read a paragraph via scrit?

I'd lile to read the following file and output everything from
'NetBIOS Name Table for Host 192.168.5.10' to the first occurance of
"----------------------------------------"

can perl do that? here is the file (long file but only the portion of
it is shown here)


----------------------------------------
data
data
----------------------------------------
NetBIOS Name Table for Host 192.168.5.11
lines1
line2

Adapter address: 00-00-00-00-00-00
----------------------------------------

NetBIOS Name Table for Host 192.168.5.10

Adapter address: 00-a8-34-35-c3-aa
----------------------------------------
more data
more data
----------------------------------------
Jul 19 '05 #1
3 3157
NNTP wrote:
I'd lile to read the following file and output everything from
'NetBIOS Name Table for Host 192.168.5.10' to the first occurance of
"----------------------------------------"

can perl do that?
sure, but can you do it?
here is the file (long file but only the portion of
it is shown here)


Read about perl slurp mode, and multi line matching.

You can also read the file line by line, setting a $state variabele to
zero before you start to read, and when you "see" the NetBIOS (see:
perldoc -f index), set $state to 1, and print the line, and every line
after if $state == 1, except when you "see" the ---- stuff. Then you set
the state back to 0.

--
John personal page: http://johnbokma.com/

Freelance Perl / Java developer available - http://castleamber.com/
Jul 19 '05 #2
joe
ne******@yahoo.com (NNTP) writes:
I'd lile to read the following file and output everything from
'NetBIOS Name Table for Host 192.168.5.10' to the first occurance of
"----------------------------------------"

can perl do that? here is the file (long file but only the portion of
it is shown here)


Sure, but awk is probably easier, and awk is more likely to be on any
given machine.

awk '/^NetBIOS Name Table/,/^----------------------------------------/' data

Joe
--
If people don't want to come out to the ballpark, nobody's going
to stop them.
- Yogi Berra
Jul 19 '05 #3
NNTP <ne******@yahoo.com> wrote in comp.lang.perl.misc:
I'd lile to read the following file and output everything from
'NetBIOS Name Table for Host 192.168.5.10' to the first occurance of
"----------------------------------------"

can perl do that? here is the file (long file but only the portion of
it is shown here)


----------------------------------------
data
data
----------------------------------------
NetBIOS Name Table for Host 192.168.5.11
lines1
line2

Adapter address: 00-00-00-00-00-00
----------------------------------------

NetBIOS Name Table for Host 192.168.5.10

Adapter address: 00-a8-34-35-c3-aa
----------------------------------------
more data
more data
----------------------------------------


Make the line of dashes the record terminator:

$/ = "----------------------------------------\n";
/\QNetBIOS Name Table for Host 192.168.5.10/ and print while <DATA>;

Anno
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Anthony Liu | last post: by
3 posts views Thread by xscully | last post: by
19 posts views Thread by Holger Hasselbach | last post: by
1 post views Thread by Jean-François Michaud | last post: by
3 posts views Thread by gentsquash | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.