I want to delete specific two consecutive lines matching patterns from specific line from a file.
For e.g. file contents are like below.
Line1: a
Line2: b
Line3: c
Line4: Name: 123
Line5: xyz
Line6: Name: 456
Line7: abc
I want to find the lines starting from line 4, matching 1st line pattern starting with "Name: " and matching 2nd line pattern starting with whitespace and delete the two consecutive lines.
Any efficient way to do this in shell using sed
or something else?
To be a bit more clear, I want to remove signing/checksum information from the MANIFEST.MF.
Sample MANIFEST.MF like below: From the below manifest file, I want to remove the entry "Name: ". where "Name: " entry can be in one line or 2(or more) lines.
Initially my solution was like find the first "Name: " entry followed by "SHA-256-Digest: " entry and delete to the end of the file. Unfortunately this solution has a problem of removing one needed entry in the middle. For e.g. "NetBeans-Simply-Convertible: " is also being removed.
So, now I want to remove "Name: " entry if available in 1 line or entry spanned across 2 or more lines. But I should not lose entries like "NetBeans-Simply-Convertible: " while removing "Name: " entries.
Already I am removing "SHA-256-Digest: " entries with the below command on file with sed -i "/^\SHA-256-Digest: /d" $manifest_file
Manifest-Version: 1.0
Version-Info:
....
Name: com/abc/xyz/pqr/client/relationship/message/notifier/Relati
onshipUpdateNotifierFactory.class
SHA-256-Digest: cSSyk6Y2L2F9N6FPtswUkxjF2kelMkGe4bFprcQ+3uY=
Name: com/abc/xyz/pqr/client/relationship/ui/BaseRelationshipView
$5.class
SHA-256-Digest: w9HgRjDuP024U4CyxeKPYFe6rzuzxZF3b+9LVG36XP8=
Name: com/abc/xyz/pqr/client/impl/MofRelationshipAgentImpl.class
SHA-256-Digest: GwIBIU+UdPtjyRhayAVM90Eo+SwCT/kP65dI59adEnM=
Name: com/abc/xyz/pqr/client/settings/ConvertibleProperties.class
NetBeans-Simply-Convertible: {com/abc/xyz/pqr/client/settings}Con
vertibleProperties
SHA-256-Digest: 5FszAtfpPXcLx/6FBWbfeg6E4fwFMRozV+Q+3rReATc=
...
Expected Output:
Manifest-Version: 1.0
Version-Info:
....
NetBeans-Simply-Convertible: {com/abc/xyz/pqr/client/settings}Con
vertibleProperties
...