Use sed to remove characters in front of matching keywords

Matthew

I have a text that looks like the following.

<DIV>SOFTWARE V1.0.1.0.RDZCUAJ DOWNLOAD</DIV>
<DIV>...</DIV>
<DIV>...</DIV>
<DIV>SOFTWARE V1.0.2.0.VWZMXQE DOWNLOAD</DIV>
<DIV>...</DIV>
<DIV>...</DIV>
<DIV>SOFTWARE V1.0.3.0.GSVZQKE DOWNLOAD</DIV>
<DIV>...</DIV>
<DIV>...</DIV>
<DIV>SOFTWARE V1.0.4.0.UIUVAZD DOWNLOAD</DIV>
<DIV>...</DIV>
<DIV>...</DIV>
<DIV>SOFTWARE V1.0.5.0.ELBXBGB DOWNLOAD</DIV>
<DIV>...</DIV>
<DIV>...</DIV>

I need to remove the 8 characters in front of DOWNLOAD</DIV>, it eventually looked like this.

<DIV>SOFTWARE V1.0.1.0 DOWNLOAD</DIV>
<DIV>...</DIV>
<DIV>...</DIV>
<DIV>SOFTWARE V1.0.2.0 DOWNLOAD</DIV>
<DIV>...</DIV>
<DIV>...</DIV>
<DIV>SOFTWARE V1.0.3.0 DOWNLOAD</DIV>
<DIV>...</DIV>
<DIV>...</DIV>
<DIV>SOFTWARE V1.0.4.0 DOWNLOAD</DIV>
<DIV>...</DIV>
<DIV>...</DIV>
<DIV>SOFTWARE V1.0.5.0 DOWNLOAD</DIV>
<DIV>...</DIV>
<DIV>...</DIV>

Is it possible to do this with the sed or awk command?

Any help is appreciated in advance!

Andy Dalton

A very simple approach is the following:

$ sed 's,.........DOWNLOAD</DIV>, DOWNLOAD</DIV>,g' input.txt
<DIV>SOFTWARE V1.0.1.0 DOWNLOAD</DIV>
<DIV>...</DIV>
<DIV>...</DIV>
<DIV>SOFTWARE V1.0.2.0 DOWNLOAD</DIV>
<DIV>...</DIV>
<DIV>...</DIV>
<DIV>SOFTWARE V1.0.3.0 DOWNLOAD</DIV>
<DIV>...</DIV>
<DIV>...</DIV>
<DIV>SOFTWARE V1.0.4.0 DOWNLOAD</DIV>
<DIV>...</DIV>
<DIV>...</DIV>
<DIV>SOFTWARE V1.0.5.0 DOWNLOAD</DIV>
<DIV>...</DIV>
<DIV>...</DIV>

That replaces 9 characters in front of DOWNLOAD</DIV> and replaces it with DOWNLOAD</DIV>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

sed remove a line matching a pattern if not after another matching pattern

sed - Remove all of a line except matching pattern

sed to remove all characters except letters and '

How to remove # in front of a line with sed?

Remove characters between two patterns using sed

Sed remove MAC address indicated by lines including keywords

GNU sed matching lines with unescaped characters

sed not matching pattern in presence of unidentified characters

How to remove characters from a matching string?

Remove escape characters using sed

Remove characters from string with sed

sed remove special characters and spaces in line

Remove all lines in single file NOT matching keywords aligned in first column

Using sed to replace/remove accented Latin characters

SED; adding # in front of matching line with various special characters

Remove exact matching word using sed

How can I properly use sed to remove text outside "" characters?

sed:remove characters after matched Nth characters

Power Query Function to search for matching keywords in a table of lists and return the text in the cel in front of the matching row

remove characters from the strings matching pattern postgresql

Remove string between two space characters with sed

How to use sed or another command line function to remove . between characters

use sed to match on string but not remove anything past any number of specific characters then a character

How to remove matching characters between two columns

How to use sed to remove some characters from file?

sed delete a line matching a pattern with special characters

Extract Keywords with the # in front of the characters

Remove all matching characters from the beginning of word

Can sed remove 'double' newline characters?