RE: [SLE] [Somewhat OT] Getting the middle part of a file.
Hi,
From: The Purple Tiger [mailto:Jon@tigersden.demon.co.uk] Hey all, This is a bit OT, but not so OT as to go to the OT list IMHO :)
I don't know if you already have a solution for this problem, but you can try this little script: ----ScriptStart #!/usr/bin/perl -w use strict; my $starttag="xxxx"; my $endtag="yyyy"; my $toggle=0; while (<STDIN>){ if ($_ =~ /$starttag/) { $toggle or $toggle=1; } elsif ($_ =~ /$endtag/){ $toggle and $toggle=0; } else { $toggle && print $_; } } exit 0; -----ScriptEnd cheers, Stefan
System is SuSE8.2
What I am trying to do: I have a large number of html files that have a segment in them I would like to copy out and save to another file.
The segment I want is after a unique table tag [unique in that whilst there are other table tags, there are none like this one, and it is the same in each file]. I want to capture up until the closing table tag.
ALSO I am trying to make sure that the first 4 lines [if you include the table tag] and the last 4 lines [if you include the closing tag] don't get copied to the file :)
I don't ask for much, do I? ;)
What I have discovered so far: I can use: grep -i "table tag stuff goes here"
to get the first line, without case mattering [which isn't essential as I think they are all exactly the same, but just in case...]. I can even: grep -iA 10 "table tag stuff goes here"
to get the 10 lines of output including the matching line.
I can use -B instead to get the 10 lines preceding the table tag at the end, if it is unique [which the closing tag isn't].
Anyone have any good 1 or 2 liners that would help me out here? Or maybe something a bit longer :)
Thanks for reading this :)
-- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
participants (1)
-
Peer Stefan