UncleKing
UncleKing

Reputation: 743

Replace Text in multiple files

I want to support android RTL and want a quick way to add support RTL in a bunch of xml
so essentially what i want is to replace

android:paddingLeft = 10dp  < !-- here 10dp can be anything else -->

with

android:paddingLeft = 10dp
android:paddingStart = 10dp

I have seen multiple examples with grep and sed which can do text replace, but here i need to extra text to be retained and copied in the next line as well..

I am sure i can do this in notepad++ and/or write a simple java code.. but looking for a simple solution.

Upvotes: 0

Views: 86

Answers (1)

jkshah
jkshah

Reputation: 11713

Using sed

sed -r 's/(android:paddingLeft(\s*=\s*\w+))/\1\nandroid:paddingStart\2/g' file

regex101 demo for test and explanation

Upvotes: 1

Related Questions