I have a bat file that I should use to delete a part of one file and save into another one. I need to delete all the symbols between text ‘[aaa bbb]’ and ‘[ccc ddd]’. That is if I have the text:
[aaa bbb] 1 2 3 [ccc ddd]
I should have as output:
[aaa bbb] [ccc ddd]
Thank you
EDIT: I would like to clarify the question. I should delete all the symbols between marker1 and marker2. Marker1 and marker2 are just some words or parts of text but not obligatory lines. For example I would have:
[aaa bbb] [ccc] 1 2 3 4 5 [www yyy]
If I want to delete the text between [aaa bbb] and [www yyy] I should have as output:
[aaa bbb] [www yyy]
Take a look at the section ‘Delete between marker 1 and marker2’ on this sed hints page
Applying it on your example. clean.sed:
Run using:
To edit the input file ‘in place’, use the -i option to sed:
A backup copy of the file with the name ‘datafile.txt.bak’ is saved before editing the original.
EDIT: Since the assumption that the markers where always on a line of their own was wrong, heres a script that can handle markers in the middle of a line:
For this input:
It produces:
Note! It can’t handle files where the markers can appear on the same line.
EDIT again: If the input format for marker 1 is such that you can always count on it being on a line of its own you can simplify the script some:
(Anchoring marker 1 at the beginning and end of a line and skipping the trimming of the marker 1 line.)