regex - Delete lines before and after a match within a specified tags in SED -
Tags
& lt;
The tag needs to be removed before and after a matching pattern & Lt; AttributeValues & gt; & Lt; AttrNames & lt; Item value = "MyContact_c" /> & Lt; / AttrNames & gt; & Lt; / AttributeValues & gt; & Lt; / MDS: insert & gt; Using
sed -i -n / / MyContact_c / {s /.*/; x; d;}; x; p ; $ {X; P;} '$ file
removes only the row before and after the mailing pattern, to remove all the contents within the MDS: Add tags ... No hint Will be useful.
this is not sed
, but there is a File >> using the snippet posted as the file content for the file
: kitsune: ~ $ printf '% s \ n' 'Set ic 1; / = "MyContact_c" / & lt; |? & Lt; Mds: insert? +; / & Lt; \ / Mds: insert & gt; / - d% p '| Ex -s $ file
Output:
& lt; Mds: insert & gt; & Lt; / MDS: insert & gt;
After removing the first instance of this section, it will print the residue of the file. If you want this to be done for all examples, then the command line will look like this:
'Set ICG / =' MyContact C '/ & lt; | & Lt; Mds: insert? +; / & Lt; \ / Mds: insert & gt; / - d% p '
If you want to do multiple files you can use it in the loop of the shell script. Naturally you would like a backup copy if you do so, make sure to copy the file before changing it, if you want to overwrite it.
By the way, if you have ever used Vim or even, vi, these types of commands are used for saving, leaving, etc. It's worth adding to the ex
in your IEHO knowledge toolbox.
Edit
Sea Shell users can not use these commands because they are quoted in Newline, which are not allowed in the C shell. Instead, you can modify the first command like this:
Kitson: ~% printf '% s \ n% s \ n% s \ n' 'set IC' '1 ; / = "MyContact_c" / & lt; |? Lt; Mds: insert? + /; & Lt; \ / Mds: insert & gt; / - d ''% p '| Pre-S $ file
You can do this with the same string.
Disclaimer: I am not a shell user myself, so maybe there is a better way, but I do not know.
Comments
Post a Comment