It seems to me that sed & awk are single line based ?
I want to delete blocks of text which look like:
<opening pattern>
<2 to 5 lines>
<closing pattern>
If I use the <2 to 5 lines>, I can avoid deleting all the good
stuff, up to the 'next' <closing pattern> in case the assumed
<closing pattern> is missing/undetected.
Thanks for any feedback,
== Chris Glur.
|
|
0
|
|
|
|
Reply
|
problems
|
3/20/2008 3:55:05 PM |
|
On Mar 20, 7:55 am, problems@gmail wrote:
> It seems to me that sed & awk are single line based ?
>
> I want to delete blocks of text which look like:
> <opening pattern>
> <2 to 5 lines>
> <closing pattern>
>
> If I use the <2 to 5 lines>, I can avoid deleting all the good
> stuff, up to the 'next' <closing pattern> in case the assumed
> <closing pattern> is missing/undetected.
>
> Thanks for any feedback,
>
> == Chris Glur.
ex is well suited for this kind of edit. ex is the command line part
of vi (what you type at the colon). I'm busy right now but if you
google
ex edit tutorial
you should see how to use it.
|
|
0
|
|
|
|
Reply
|
A
|
3/20/2008 4:21:32 PM
|
|
On Thu, 20 Mar 2008 10:55:05 -0500, problems wrote:
> It seems to me that sed & awk are single line based ?
>
> I want to delete blocks of text which look like: <opening pattern>
> <2 to 5 lines>
> <closing pattern>
>
> If I use the <2 to 5 lines>, I can avoid deleting all the good stuff, up
> to the 'next' <closing pattern> in case the assumed <closing pattern> is
> missing/undetected.
>
> Thanks for any feedback,
>
Pseudocode:
if line matches opening pattern, set flag
if flag is clear, print line
if line matches closing pattern, clear flag
If you want to keep the two pattern lines, interchange the locations of
the two tests.
--
T.E.D. (tdavis@mst.edu)
|
|
0
|
|
|
|
Reply
|
Ted
|
3/20/2008 7:55:29 PM
|
|
On 2008-03-20, problems@gmail <problems@gmail> wrote:
> I want to delete blocks of text which look like:
><opening pattern>
><2 to 5 lines>
><closing pattern>
> Thanks for any feedback,
Try these for ideas. See the "SELECTIVE DELETION OF CERTAIN LINES:"
section.
http://www.eng.cam.ac.uk/help/tpl/unix/sed.html
nb
|
|
0
|
|
|
|
Reply
|
notbob
|
3/20/2008 8:12:01 PM
|
|
On 3/20/2008 10:55 AM, problems@gmail wrote:
> It seems to me that sed & awk are single line based ?
sed is line-based, awk is record-based.
> I want to delete blocks of text which look like:
> <opening pattern>
> <2 to 5 lines>
> <closing pattern>
Use:
awk -v RS="<closing pattern>" '...' file
to use "<closing pattern>" as the record separator.
> If I use the <2 to 5 lines>, I can avoid deleting all the good
> stuff, up to the 'next' <closing pattern> in case the assumed
> <closing pattern> is missing/undetected.
Post some sample input and expected output for more help.
Ed.
|
|
0
|
|
|
|
Reply
|
Ed
|
3/20/2008 10:26:02 PM
|
|
awk can definitely understand multi-line patterns. All that you have to do
is set the RS (record separator) variable. The best place to do this would
be in the BEGIN however you can change this anytime during the execution.
The best part is RS can also be a regular expression like RS="</[^>]*>" .
<problems@gmail> wrote in message news:1206028330.11645@vasbyt.isdsl.net...
> It seems to me that sed & awk are single line based ?
>
> I want to delete blocks of text which look like:
> <opening pattern>
> <2 to 5 lines>
> <closing pattern>
>
> If I use the <2 to 5 lines>, I can avoid deleting all the good
> stuff, up to the 'next' <closing pattern> in case the assumed
> <closing pattern> is missing/undetected.
>
> Thanks for any feedback,
>
> == Chris Glur.
>
|
|
0
|
|
|
|
Reply
|
Rajan
|
3/23/2008 11:28:19 PM
|
|
|
5 Replies
382 Views
(page loaded in 0.065 seconds)
Similiar Articles: extracting a particular pattern from a line - comp.unix.shell ...Also, if you want to match multiple occurrences of each pattern on a single line, just add ... Extract a specific pattern from lines with sed, awk or perl ... Can I use sed if ... gawk problem matching multiple patterns ?!? HOW-TO? - comp.lang ...Join two lines in pattern matching, search, then ... AWK: Multiple patterns per line - The UNIX and ... ... AWK/SED Multiple pattern matching over multiple lines issue AWK/SED ... add line on a file with sed or awk - comp.unix.solaris... how to merge multiple lines into one line - comp.lang.awk ... add line on a file with sed ... ... last field of line (cut/sed/awk ... sed replace string when line match something ... sed, remove last new line - comp.lang.awkThat's a special case. sed works by reading each line into the pattern ... select last field of line (cut/sed/awk ... sed replace string when line match something - comp.unix ... print lines between two patterns - comp.lang.awk... is simplest way of doing it with awk or sed or ... Join two lines in pattern matching, search, then ... separated by spaces or commas ... multi-line block is in the pattern ... regex match multiple words in a line - comp.databases.mysql ...... that looks for a multiple word match in one line ... line - comp.lang.awk sed replace string when line match ... Matching Multi-Line Regular Expression Patterns In MULTILINE Mode ... How to filter out lines? - comp.lang.awk... multiline patterns I think grep is not a right choice. How it can be done with awk/sed? ... comment out multiple lines in kshell? - comp.unix ... I can do # to do one line ... pattern match and dw in vim - comp.unix.admin... end of every line from the last - onwards. Can I pattern match ... comp.lang.awk ... pattern match and ... when line match something - comp.unix.shell ... sed and Multi-Line ... how to merge multiple lines into one line - comp.lang.awk ...Providing total bytes do not exceed sed's pattern space ... commands on one line? - comp.os ... how to merge multiple lines into one line - comp.lang.awk ..... the sed ... sed: printing only between {} - comp.unix.shellprint lines between two patterns - comp.lang.awk Unix Sed Tutorial ... Brooklyn How would I print only lines match ... line instead of printing whole line using awk/sed ... Can awk, sed match mult-line patterns ? - Application Forum at ...Can awk, sed match mult-line patterns ? - awk . This is a discussion on Can awk, sed match mult-line patterns ? - awk; It seems to me that sed & awk are single ... AWK/SED Multiple pattern matching over multiple lines issueLinuxQuestions.org > Forums > Non-*NIX Forums > Programming: AWK/SED Multiple pattern matching ... One more tip: All your lines begins with 2006... so you can use it as a line ... 7/20/2012 9:49:39 PM
|