0

I have a change I need to make across multiple different sites and may need to make again in the future, so I'd like to put it in a shell script. Essentially I want to find a specific class block in a css file, find one of its attributes and change the value of that attribute.

So for example:

.some-id {
  some-arbitrary-properties
  property-i-want: old-value
  maybe-some-more-properties
}

I want to only change old-value in property-i-want, and only if it's in .some-id.

I'm very comfortable with grep, but it only works one line at a time. I'm somewhat less comfortable with sed, but I haven't seen any way to do this without a deterministic set of properties. For instance, I could have sed replace the entire block. But I want to leave any other properties in the block alone.

I'd rather not use perl or python, but I can. I'd like to keep it short, because it's going in a script of one-liners.

Keith
  • 4,637
  • 15
  • 25
TBridges42
  • 101
  • 2

1 Answers1

1

Write a small program using a CSS library in whatever language. You mentioned Perl, perhaps CSS::Tiny.

One-liners are overrated, can be difficult to read. Selecting a style, reading a property, changing a property if a condition, these are more than one step.

John Mahowald
  • 32,050
  • 2
  • 19
  • 34