Skip to content
Advertisement

Changing contents of a tsx file through shell script

I have a requirement to change the contents of config.tsx file that contains values like:

const authData = {
    base_uri: 'https://development-api.com.au',

    customLib: {
        redirect_uri: 'https://another-development-api.com.au'
    }
}
export default authData;

I want to change this content using a shell script and save the file. Changed content can look like:

const authData = {
    base_uri: 'https://production-api.com.au',

    customLib: {
        redirect_uri: 'https://another-production-api.com.au'
    }
}
export default authData;

How can I do this?

Advertisement

Answer

This should work:

sed -i 's/development/production/g' config.tsx

The -i option will edit the file in place. If you first want to try the command to see if it works the way you want, use it without the -i. The output will be printed to stdout.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement