0

I have a file that contains a total of 482 lines i want to remove ~~adt*~~ from. This is how the content looks like:

478|~~adt00000aa9~~~~adt0000000b~~14395189_p0.jpg
479|~~adt00000995~~44836628_p0.jpg
480|~~adt00000aae~~Miku_Collab_2_by_Luciaraio.jpg

I tried sed 's/~~adt*~//' file > new_file but it didn't remove everything.

How can i remove everything between the first and the last two ~~ signs?

  • Replace * by .*? – Cyrus Sep 7 '17 at 19:11
2

Given that you want to remove ~~adt(something)~~ and that there may be ~~(something different)~~ on other lines (not shown in the question):

$ sed 's/~~adt[^~]*~~//g' file.in >file.out

For the given data, this will generate

478|14395189_p0.jpg
479|44836628_p0.jpg
480|Miku_Collab_2_by_Luciaraio.jpg

Changing the adt of the last line to xxx, the command generates

478|14395189_p0.jpg
479|44836628_p0.jpg
480|~~xxx00000aae~~Miku_Collab_2_by_Luciaraio.jpg

The pattern ~~adt[^~]*~~ will match all occurrences of ~~adt followed by any number of characters that are not ~, and then ~~ again. The /g at the end will ensure that all such matches on every line are removed.

1

adt* means a followed by d followed by any number of t's including 0.

Dot matches any character, so use

~~adt.*~

To match ~~adt followed by any number (including 0) of characters, followed by ~.

1

You could try this:

sed 's/~.*~//' file > file_new

Output will:

478|14395189_p0.jpg
479|44836628_p0.jpg
480|Miku_Collab_2_by_Luciaraio.jpg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.