hello all,
I have a file like this:
and I want to use sed to duplicate section 2, like this:
I've figured out that I can do this:
and it will return:
but I can't get it to drop the last line, and I can't get my regexp to say grab UNTIL you get to the word section, since thats marking the line. Help please, I've been reading the sed tutorials and man pages endlessly and now I'm just going in circles.
Last edited by nick26; 04-29-2008 at 09:23 AM..
Reason: spacing
The real hurdle is in expressing more complex logic than "from here through to here". But sed is a programming language, just rather primitive, and very terse (or "succinct", or "unreadable", depending on how you look at it).
So to paraphrase, between section 2 and section 3, you want to print, but not if it's section 3. If expressed this way, it's easy (just not very elegant):
Incidentally, in your original script, the braces were not necessary, but now they are, because there's a block of multiple things we want to happen when the first condition matches.
Just to complete it, why don't you collect section 2 into the hold space, and print it out a second time when you see the section 3 heading:
So if we are between section 2 and section 3 (inclusive); then if we are not looking at section 3, append to hold space, and skip to the end of the current script (where the line is implicitly printed the first time); else, recall what's in the hold space, remove the first item (which is empty, because we have been appending to the hold space, and that's what it originally contained), print, and recall back the earlier pattern space (which is the section 3 heading; again, at the end of the script, that line is printed.
This would be way more readable and maintainable in awk or Perl, mind.
Hello folks!
Raised a bump on my head trying to figure this one out ;)
I have an xml file which needs to be edited, removing an entire property section in the work. Here's what the target section layout looks like:
<property name="something">
{any number of lines go here}
</property>... (7 Replies)
Hi, I have following data in a file. Not all but most of the lines start with letter 'T' has 8 SPACES from column 121 to 128 and I want to replace that portion with some dummy value. Is it possible through sed?
Input File:-
T1111111111111A 20140310000000005076358416369283 AAAAA ... (6 Replies)
Hello.
I am trying to modify a config file which is in windows *.ini type file.
I have found a piece of code here :linux - Edit file in unix using SED - Stack Overflow
As I can't make it doing the job , I am trying to find a solution step by step.
here a modified sample file : my_sample.ini... (1 Reply)
i have a file as below that has n section :
2006 0101 1236 49.3 L 37.902 48.482 0.0 Teh 5 0.2 2.7LTeh 1
GAP=238 E
Iranian Seismological Center, Institute of Geophysics, University of Tehran 6
... (5 Replies)
I have a list of Servers in no particular order as follows:
virtualMachines="IIBSBS IIBVICDMS01 IIBVICMA01"And I am generating some output from a pre-existing script that gives me the following (this is a sample output selection).
9/17/2010 8:00:05 PM: Normal backup using VDRBACKUPS... (2 Replies)
I've been working on a script (/bin/sh) in which I have requested and received help here (in which I am very grateful for!). The client has modified their requirements (a tad), so without messing up the script to much, I come once again for assistance.
Here are the file.dat contents:
ABC1... (4 Replies)
Hello,
I need help in putting duplicate lines within a section into another file. Here is what I'm struggling with:
Using this file data.txt:
ABC1 012345 header
ABC2 7890-000
ABC3 012345 Header Table
ABC4
ABC5 593.0000 587.4800
ABC5 593.5000 587.6580 <= dup need to remove
ABC5... (4 Replies)
Hello,
I am in need of removing duplicate lines from within a file per section.
File:
ABC1 012345 header
ABC2 7890-000
ABC3 012345 Header Table
ABC4
ABC5 593.0000 587.4800
ABC5 593.5000 587.6580 <= dup need to remove
ABC5 593.5000 ... (5 Replies)
I need to get a section of a file based on 2 params. I want the part of the file between param 1 & 2. I have tried a bunch of ways and just can't seem to get it right. Can someone please help me out.....its much appreciated. Here is what I have found that looks like what I want....but doesn't... (12 Replies)