Sponsored Content
Top Forums Shell Programming and Scripting Replace Contents between 2 strings in a file with contens of another file Post 302673677 by powelltallen on Wednesday 18th of July 2012 08:46:45 AM
Old 07-18-2012
Replace Contents between 2 strings in a file with contens of another file

Please I want to replace all the contents beween "Section" and "Ensection" in file1 with all contents in file2. Example:

file1:
Code:
 
Section "Screen"
 
DefaultDepth 24
SubSection "Display"
Depth 8
ViewPort 0 0
Modes "1024x768" "800x600" "640x480"
EndSubsection
SubSection "Display"
Depth 16
ViewPort 0 0
Modes "1024x768" "800x600" "640x480"
EndSubsection
SubSection "Display"
Depth 24
ViewPort 0 0
Modes "1280x1024" "1024x768" "800x600" "640x480"
EndSubsection
 
EndSection


file2:
Code:
 
DefaultDepth 16
SubSection "Display"
Depth 8
ViewPort 0 0
Modes "1024x768" "800x600" "640x480"
EndSubsection
SubSection "Display"
Depth 16
ViewPort 0 0
Modes "640x480" "800x600" "1024x768"
EndSubsection
SubSection "Display"
Depth 24
ViewPort 0 0
Modes "1024x768" "800x600" "640x480"
EndSubsection

I want my output to be:
Code:
 
Section "Screen"
 
DefaultDepth 16
SubSection "Display"
Depth 8
ViewPort 0 0
Modes "1024x768" "800x600" "640x480"
EndSubsection
SubSection "Display"
Depth 16
ViewPort 0 0
Modes "640x480" "800x600" "1024x768"
EndSubsection
SubSection "Display"
Depth 24
ViewPort 0 0
Modes "1024x768" "800x600" "640x480"
EndSubsection
 
Endsection

Please how can I do this?
Kind regards


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by zaxxon; 07-18-2012 at 09:53 AM.. Reason: code tags, see PM
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read file and for each line replace two variables, add strings and save output in another file

Hi All, I have a file, let's call it "info.tmp" that contains data like this .. ABC123456 PCX333445 BCD789833 I need to read "info.tmp" and for each line add strings in a way that the final output is put /logs/ua/dummy.trigger 'AAA00001.FTP.XXX.BLA03A01.xxxxxx(+1)' where XXX... (5 Replies)
Discussion started by: Andy_ARG
5 Replies

2. Shell Programming and Scripting

replace a string with contents of a txt file containing multiple lines of strings

Hello everyone, ive been trying to replace a string "kw01" in an xml file with the contents of a txt file having multiple lines. im a unix newbie and all the sed combinations i tried resulted to being garbled. Below is the contents of the txt file: RAISEDATTIME --------------------... (13 Replies)
Discussion started by: 4dirk1
13 Replies

3. UNIX for Dummies Questions & Answers

How to search two strings in a file and print the contents in between to a file

I have a file called po.txt. Here is the content of the file: <!DOCTYPE PurchaseOrderMessage (View Source for full doctype...)> - <PurchaseOrder> - <Header> <MessageId>cdb3062b-685b-4cd5-9633-013186750e10</MessageId> <Timestamp>2011-08-01T13:47:23.536-04:00</Timestamp> </Header> -... (4 Replies)
Discussion started by: webbi
4 Replies

4. Shell Programming and Scripting

script to grep a pattern from file compare contents with another file and replace

Hi All, Need help on this I have 2 files one file file1 which has several entries as : define service{ hostgroup_name !host1,!host5,!host6,.* service_description check_nrpe } define service{ hostgroup_name !host2,!host4,!host6,.* service_description check_opt } another... (2 Replies)
Discussion started by: namitai
2 Replies

5. Shell Programming and Scripting

Replace partial contents of file with contents read from other file

Hi, I am facing issue while reading data from a file in UNIX. my requirement is to compare two files and for the text pattern matching in the 1st file, replace the contents in second file by the contents of first file from start to the end and write the contents to thrid file. i am able to... (2 Replies)
Discussion started by: seeki
2 Replies

6. Shell Programming and Scripting

Run a program-print parameters to output file-replace op file contents with max 4th col

Hi Friends, This is the only solution to my task. So, any help is highly appreciated. I have a file cat input1.bed chr1 100 200 abc chr1 120 300 def chr1 145 226 ghi chr2 567 600 unix Now, I have another file by name input2.bed (This file is a binary file not readable by the... (7 Replies)
Discussion started by: jacobs.smith
7 Replies

7. Shell Programming and Scripting

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

8. Shell Programming and Scripting

Replace the .txt file between two strings in XML file

Hi i am having XML file with many number of lines,I need to replace between two strings with .txt file using awk. For ex <PersonInfoShipTo ------------------------------ /> My requirement is to replace the content between <PersonInfoShipTo ------------------------------ /> help me. Thanks... (9 Replies)
Discussion started by: Padmanabhan
9 Replies

9. Shell Programming and Scripting

How to replace a string in a file with contents of another file?

Hi, I have to replace a string in my first file with contents of second file. Second file has 5 lines in it. file1.txt This is the first file. LineToBeReplaced This is the last line of the first file. file2.txt This is line1 of the second file. This is line2 of the second file.... (3 Replies)
Discussion started by: vijay14
3 Replies

10. Emergency UNIX and Linux Support

sed replace file contents by reading from another file

Hello, My input file1 is like this by tab-delimited chr1 mm10_knownGene stop_codon 3216022 3216024 0.000000 - . gene_id "uc007aeu.1"; transcript_id "uc007aeu.1"; chr1 mm10_knownGene CDS 3216025 3216968 0.000000 - 2 gene_id "uc007aeu.1"; transcript_id "uc007aeu.1"; ... (3 Replies)
Discussion started by: jacobs.smith
3 Replies
All times are GMT -4. The time now is 06:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy