Skip to content

Category: english

Installing a Cooler Master Hyper 212 Led (CPU cooler). This thing is way bigger than I thought..
Instagram: http://ift.tt/2mB0T4Q

@electricpants @therealadamsavage @braincandylive #tested #vsauce.
Instagram: http://ift.tt/2mNolN5

Finally in my hands, Zelda Breath of the Wild!

#wiiu #zelda #botw #amazonprime.
Instagram: http://ift.tt/2lVuPVE

#7wonders #boardgame.
Instagram: http://ift.tt/2m6BEoP

Replacing with SED and regexes

Let’s say you have a html file called file.html and you want to replace “.jpg” to “.png” but only when in a href of anchor elements.

Example of input:
[html]<a href="alice.jpg">alice<a>
<a href="bob.jpg">bob<a>
something.jpg
href.jpg
<a href="example.com">alice.jpg</a>
<img src="href.jpg">
[/html]

Desired output:
[html]<a href="alice.png">alice<a>
<a href="bob.png">bob<a>
something.jpg
href.jpg
<a href="example.com">alice.jpg</a>
<img src="href.jpg">
[/html]

Notice that only the first two references to “.jpg” were changed to “.png”, the ondes in the href of the anchor.

You can use sed with regexes to achieve this.
[bash]
sed -i -E ‘s/(<a href=".*).jpg(")/\1.png\2/’ file.html
[/bash]

Where:

  • -i for editing the files in-place
  • -E to use a script
  • s// substitute
  • (<a href=”.*) group 1, the string ‘<a href=”‘ followed of any character zero or more times
  • .jpg the .jpg we want to replace
  • (“) group 2, only “
  • \1.png\2 substitute with the same group 1 then .png then the group 2.

“Love forever” by Yayoi Kusama. Plus my head.
#infinitekusama #hirshhorn.
Instagram: http://ift.tt/2lUotaw

#infinitekusama #hirshhorn.
Instagram: http://ift.tt/2mCeTck

#infinitekusama #hirshhorn.
Instagram: http://ift.tt/2m4RSB5

#infinitekusama #harpersferry.
Instagram: http://ift.tt/2mCbZVb