通过 shell 脚本更改 tsx 文件的内容

Changing contents of a tsx file through shell script

我需要更改 config.tsx 文件的内容,其中包含以下值:

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

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

我想使用 shell 脚本更改此内容并保存文件。更改后的内容可能如下所示:

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

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

我该怎么做?

这应该有效:

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

-i 选项将就地编辑文件。如果您首先想尝试该命令以查看它是否按您想要的方式工作,请在不使用 -i 的情况下使用它。输出将打印到标准输出。