in reply to Re^5: Reading multiple lines from text file
in thread Reading multiple lines from text file

Ah thanks!! but the key is not the last word on the line!! in fact that was my previous comment, but I removed it since I figured a way to grep it from the middle of the line.The key column can be any where ,not necessarily last....what should be the adaptation now.
aaa23 fgfgdf test pppp Released bbb34 fgfgdf test pppp Released dfsad324 fgfgdf test pppp Released efdewr23 fgfgdf dev pppp Released dsarfew234 fgfgdf dev pppp skip dqewr2321 fgfgdf prod pppp skip sdsw32 fgfgdf prod pppp Released asdw234 fgfgdf prod pppp Released sadw2342 fgfgdf qa pppp Released deww234 fgfgdf qa pppp Released qdrqew234 fgfgdf qa pppp block swd234 fgfgdf manage pppp Released swdq234 fgfgdf manage pppp Released dfwfr43 fgfgdf manage pppp Released drqewr234 fgfgdf manage pppp Released

2018-08-19 Athanasius added code tags

Replies are listed 'Best First'.
Re^7: Reading multiple lines from text file
by Athanasius (Cardinal) on Aug 09, 2018 at 07:07 UTC

    Hello again newperlbie,

    (1) Please read Markup in the Monastery “Chapter 1” and update your post accordingly.

    (2) “in fact that was my previous comment, but I removed it

    In future, please use <strike>...</strike> tags around discarded text rather than deleting it. Also clearly mark any updates as such. This will reduce the likelihood of confusion for responders to your posts.

    (3) “I figured a way to grep it from the middle of the line.

    Good! (But then, why the next question?)

    (4) “The key column can be any where ,not necessarily last....what should be the adaptation now.

    Can the key column change from one line to another? Is it guaranteed that the key words will never appear accidentally in non-key positions within a line? If so, you can just test for the presence of a keyword anywhere in the line with a simple regular expression:

    while (<DATA>) { if (/\b$first\b/ .. /\b$last\b/) { $in = 1; print; } elsif ($in && /\b$last\b/) { print; } else { $in = 0; } }

    (In a regex, \b matches a word boundary.)

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re^7: Reading multiple lines from text file
by AnomalousMonk (Archbishop) on Aug 09, 2018 at 13:40 UTC