Computing.Net > Forums > Unix > SED - Insert a new line in middle

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

SED - Insert a new line in middle

Reply to Message Icon

Name: Arunkumar
Date: April 25, 2009 at 00:16:05 Pacific
OS: HP-UX
Subcategory: General
Comment:

Hi,

I am new to sed. Can anybody please solve my problem.

The following lines are input line.

*****************************************
ABCD SECTION.
*****************************************

CALL "XYZ".

Output Required as follows :

*****************************************
ABCD SECTION.
*****************************************
COPY COPYBOOK. ----> (New line has to inserted here.)
CALL "XYZ".

The "COPY COPYBOOK" line has to be appended after finding ABCD Section and the STARS Line only. (Not above the Stars Line)

Thanks in Advance for solving this.

Arun




Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: April 27, 2009 at 02:03:01 Pacific
Reply:

awk

awk '/ABCD/{print;getline; if ($0~/\*\*\*/){print;print "COPY COPYBOOK"};next }1' file

Unix Win32 tools | Gawk for Windows


0

Response Number 2
Name: Arunkumar
Date: April 27, 2009 at 06:38:13 Pacific
Reply:

Thank you very much.....ghost...it works fine.


0

Response Number 3
Name: Arunkumar
Date: April 27, 2009 at 08:32:18 Pacific
Reply:

Hi,
Using the above example, how we can able to paste the "COPY COPYBOOK" at above the ABCD SECTION and Stars line.

Output required:

COPY COPYBOOK. ----> (New line has to inserted here.)
*****************************************
ABCD SECTION.
*****************************************

CALL "XYZ".


Thanks
Arun


0

Response Number 4
Name: ghostdog
Date: April 27, 2009 at 17:37:36 Pacific
Reply:

first try to look for other patterns above ABCD section. is there any other text above ABCD?

Unix Win32 tools | Gawk for Windows


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: SED - Insert a new line in middle

vi : insert a string every 2nd line www.computing.net/answers/unix/vi-insert-a-string-every-2nd-line/8251.html

Adding a new string in a file www.computing.net/answers/unix/adding-a-new-string-in-a-file/8060.html

Unix Sed - inserting new lines www.computing.net/answers/unix/unix-sed-inserting-new-lines/6487.html