Sponsored Content
Top Forums Shell Programming and Scripting Using Sed to duplicate a section of a file.... Post 302190267 by nick26 on Tuesday 29th of April 2008 08:20:40 AM
Old 04-29-2008
Using Sed to duplicate a section of a file....

hello all,
I have a file like this:
Code:
section 1
blah1
blah2
section 2
blah1
blah2
section 3
blah1
blah2

and I want to use sed to duplicate section 2, like this:
Code:
section 1
blah1
blah2
section 2
blah1
blah2
section 2
blah1
blah2
section 3
blah1
blah2

I've figured out that I can do this:
Code:
sed -n '/section 2/,/section/{ p }' input_file

and it will return:
Code:
section 2
blah1
blah2
section 3

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
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed & awk--get section of file based 2 params

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)
Discussion started by: Andy Cook
12 Replies

2. Shell Programming and Scripting

Removing Duplicate Lines per Section

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)
Discussion started by: petersf
5 Replies

3. Shell Programming and Scripting

Placing Duplicate Lines per section into another file

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)
Discussion started by: petersf
4 Replies

4. Shell Programming and Scripting

Duplicate Line Report per Section

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)
Discussion started by: petersf
4 Replies

5. Shell Programming and Scripting

Extract section of file based on word in section

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)
Discussion started by: jelloir
2 Replies

6. Shell Programming and Scripting

Delete a section of a file if...

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)
Discussion started by: oreka18
5 Replies

7. Shell Programming and Scripting

Fetch a section from a file

Hi, I have a file like... $cat file1 +++++++++++++++++++ client1 +++++++++++++++++++++++++++++ col1 col2 col3 ------ ----- ----- (0 rows affected) ========================================================= +++++++++++++++++++ client1 +++++++++++++++++++++++++++++ col1 col2 col3... (6 Replies)
Discussion started by: sam05121988
6 Replies

8. Shell Programming and Scripting

sed - String substitution within specified section in ini type file

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)
Discussion started by: jcdole
1 Replies

9. UNIX for Advanced & Expert Users

How to identify particular section using sed?

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)
Discussion started by: jnrohit2k
6 Replies

10. Shell Programming and Scripting

Section Removal With sed; and With a Twist . . .

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)
Discussion started by: LinQ
7 Replies
elf_getscn(3E)															    elf_getscn(3E)

NAME
elf_getscn(), elf_ndxscn(), elf_newscn(), elf_nextscn() - get section information for ELF files SYNOPSIS
Command: [flag]... file... [library]... DESCRIPTION
These functions provide indexed and sequential access to the sections associated with the ELF descriptor elf. If the program is building a new file, it is responsible for creating the file's ELF header before creating sections; see elf_getehdr(3E). returns a section descriptor, given an index into the file's section header table. Note the first "real" section has index 1. Although a program can get a section descriptor for the section whose index is 0 the undefined section), the section has no data and the section header is "empty" (though present). If the specified section does not exist, an error occurs, or elf is null, returns a null pointer. creates a new section and appends it to the list for elf. Because the section is required and not "interesting" to applications, the library creates it automatically. Thus the first call to for an ELF descriptor with no existing sections returns a descriptor for section 1. If an error occurs or elf is null, returns a null pointer. After creating a new section descriptor, the program can use to retrieve the newly created, "clean" section header. The new section descriptor will have no associated data (see elf_getdata(3E)). When creating a new section in this way, the library updates the member of the ELF header and sets the bit for the section (see elf_flag(3E)). If the program is building a new file, it is responsible for creating the file's ELF header (see elf_getehdr(3E)) before creating new sections. takes an existing section descriptor, scn, and returns a section descriptor for the next higher section. One may use a null scn to obtain a section descriptor for the section whose index is 1 (skipping the section whose index is If no further sections are present or an error occurs, returns a null pointer. takes an existing section descriptor, scn, and returns its section table index. If scn is null or an error occurs, returns EXAMPLES
An example of sequential access appears below. Each pass through the loop processes the next section in the file; the loop terminates when all sections have been processed. scn = 0; while ((scn = elf_nextscn(elf, scn)) != 0) { /* process section */ } SEE ALSO
elf(3E), elf_begin(3E), elf_flag(3E), elf_getdata(3E), elf_getehdr(3E), elf_getshdr(3E). elf_getscn(3E)
All times are GMT -4. The time now is 11:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy