|
From: problems on 20 Apr 2008 08:19 Please help me with this frustrating/infuriating task, which I've failed to do using awk & cooledit-macros. I need to often delete repeated patterns of consecutive lines in text files, which patterns start with a line of partially known contents, and have 2 to 4 further lines, and end with a line of partially known content. eg. line1 .... asd OpenBrkt wre bad stuff 54 badstuff fdakj CloseBrkt goodline n kjkk good line .... Where I'd need to delete from line: asd OpenBrkt to line fdakj CloseBrkt inclusively. Pseudo code could be: ReadIn byLine from SrcFile till EOF. IF currentLine contains "openBraket" THEN Initialise 0 -> SkipCounter REPEAT ReadIn; INC(SkipCounter) UNTIL( SkipCounter < 4) AND (currentLine notContains "CloseBrkt") ELSE accept currentLine {eg. by not deleting} Thanks, == Chris Glur.
From: Dave B on 20 Apr 2008 08:30 On Sunday 20 April 2008 14:19, problems(a)gmail wrote: > Please help me with this frustrating/infuriating task, > which I've failed to do using awk & cooledit-macros. > > I need to often delete repeated patterns of consecutive > lines in text files, which patterns start with a line of > partially known contents, and have 2 to 4 further lines, > and end with a line of partially known content. > > eg. > line1 > ... > asd OpenBrkt > wre bad stuff > 54 badstuff > fdakj CloseBrkt > goodline n > kjkk good line > ... > > Where I'd need to delete from line: > asd OpenBrkt > to line > fdakj CloseBrkt > inclusively. > > Pseudo code could be: > ReadIn byLine from SrcFile till EOF. > IF currentLine contains "openBraket" > THEN Initialise 0 -> SkipCounter > REPEAT ReadIn; INC(SkipCounter) > UNTIL( SkipCounter < 4) > AND (currentLine notContains "CloseBrkt") > ELSE accept currentLine {eg. by not deleting} > > Thanks, > > == Chris Glur. Does awk '/OpenBrkt/,/CloseBrkt/ {next} 1' yourfile do what you want? -- D.
From: Martijn Dekker on 21 Apr 2008 15:18 In article <1208693765.269429(a)vasbyt.isdsl.net>, problems(a)gmail wrote: > Where I'd need to delete from line: > asd OpenBrkt > to line > fdakj CloseBrkt > inclusively. With sed, this can be done as follows: sed '/asd OpenBrkt/,/fdakj CloseBrkt/ d' The two 'addresses' to the 'd' command, between the pairs of slashes, are old-style regular expressions in the sense of 'grep'. See 'man 1 sed' and 'man 7 regex' for some extremely condensed documentation. You might also try the group comp.unix.shell for this type of question. - Martijn
From: Chick Tower on 21 Apr 2008 15:07 On Sun, 20 Apr 2008 07:19:04 -0500, problems wrote: > Pseudo code could be: > ReadIn byLine from SrcFile till EOF. > IF currentLine contains "openBraket" > THEN Initialise 0 -> SkipCounter > REPEAT ReadIn; INC(SkipCounter) > UNTIL( SkipCounter < 4) > AND (currentLine notContains "CloseBrkt") > ELSE accept currentLine {eg. by not deleting} I don't know awk or any particular system of pseudocode, and I'm not a bash guru, Chris, but I think I see one reason why you're having problems. It looks like your pseudocode will read the line immediately after the one containing openBraket and then it will exit the REPEAT/UNTIL loop. It looks like only those two lines will be excluded. I'm not sure why you're both counting lines and looking for CloseBrkt, but changing notContains to Contains should give you better results. -- Chick Tower For e-mail: aols2 DOT sent DOT towerboy AT xoxy DOT net
From: Eef Hartman on 22 Apr 2008 05:28 In alt.os.linux.slackware Martijn Dekker <martijn(a)inlv.demon.nl> wrote: > With sed, this can be done as follows: > > sed '/asd OpenBrkt/,/fdakj CloseBrkt/ d' ^ I don't think that SPACE should be there. It may work, but is not according to official sed syntax (the range should be directly in front of the command). And - of course - this is the command to use in a PIPE, as no filename(s) is/are given. To the OP: IF you specify a filename it is the INPUT file (cq files), the output should always be redirected to a different (not-existing yet) file, as the redirection is done before the input files can be opened, so redirecting to an existing file will empty it. -- ******************************************************************** ** Eef Hartman, Delft University of Technology, dept. EWI/TW ** ** e-mail: E.J.M.Hartman(a)math.tudelft.nl, fax: +31-15-278 7295 ** ** snail-mail: P.O. Box 5031, 2600 GA Delft, The Netherlands ** ********************************************************************
|
Pages: 1 Prev: Bookmarks frustration! Next: Does an SD/MMC Card Hotplug Freeze Linux |