Date: Tue, 4 Jan 2011 15:11:44 +0200 From: Jonathan McKeown <j.mckeown@ru.ac.za> To: freebsd-questions@freebsd.org Subject: Re: a perl question Message-ID: <201101041511.44255.j.mckeown@ru.ac.za> In-Reply-To: <117654.42578.qm@web121409.mail.ne1.yahoo.com> References: <117654.42578.qm@web121409.mail.ne1.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tuesday 04 January 2011 12:32:00 S Mathias wrote: > cat asdf.txt > bla-bla > bla-bla > bla[XYZ] > importantthing > another important thing > [/XYZ] > bla-bla > bla-bla > [XYZ] > yet another thing > hello! > [/XYZ] > bla-bla > etc. > $ SOMEPERLMAGIC asdf.txt > output.txt > $ cat output.txt > importantthing > another important thing > yet another thing > hello! This could mean almost anything (witness another response which excludes lines containing blah or XYZ, which gives the desired output on your test input). Are you actually trying to extract all the lines inside [XYZ]...[/XYZ] tags? are the tags guaranteed not to occur on the lines you need to extract, as they appear here? Because (all on one line) perl -ne 'print if ($check = m{\[XYZ\]} .. m{\[/XYZ\]}) > 1 and $check !~ /E0$/' asdf.txt >output.txt produces the same output as you have above for the test input. (The .. range operator in scalar context is true as soon as the left-hand expression is true, and false as soon as the right-hand expression is true. It returns 1 each time it becomes true, incrementing integers as it stays true, and appends E0 to the last number as it becomes false, which lets you exclude both endpoints). Jonathan
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201101041511.44255.j.mckeown>