adamreisnz / replace-in-file

A simple utility to quickly replace contents in one or more files
580 stars 65 forks source link

Is there a way to represent empty? #198

Closed xiasun closed 3 months ago

xiasun commented 3 months ago

For example I want to remove all variables with suffix _2 with empty in my file

replace-in-file /_2/g '' my-file.js

But I can't a proper way to represent empty, Is there any?

Thanks~

adamreisnz commented 3 months ago

Yes, I suggest instead of using the to parameter, you use a local .json config file instead:

replace-in-file my-file.js --configFile=config.json

config.json

{
  "from": "/_2/g",
  "to": "",
}

You can put the my-file.js in your config as well.

xiasun commented 3 months ago

Thanks, using config file is fine!