Python script that replaces strings in a file based on mappings from another file
397
This Docker image allows you to run a Python script that replaces strings in a file based on mappings from another file. It uses replace_strings.py, which reads a company.txt file containing string mappings and replaces occurrences of those strings in a voiceflow.vf file.
The script reads the company.txt file, which contains the strings that need to be replaced and their corresponding replacements. It then processes the voiceflow.vf file and replaces all occurrences of the specified strings. The output is saved in a new file named out-company-voiceflow.vf.
company.txt Structure:STRING TO BE REPLACED1||STRING TO BE USED TO REPLACE1
STRING TO BE REPLACED2||STRING TO BE USED TO REPLACE2
replace_strings.py Workflow:For instance, if company.txt contains:
old_value1||new_value1
old_value2||new_value2
And voiceflow.vf contains:
This is old_value1 and here is old_value2.
The script will replace old_value1 with new_value1 and old_value2 with new_value2, resulting in the following output in out-company-voiceflow.vf:
This is new_value1 and here is new_value2.
To build the Docker image, run the following command:
docker build -t schogini/replace-strings-image .
To run the container and execute the script:
docker run --rm -v $(pwd):/app schogini/replace-strings-image company.txt voiceflow.vf
company.txt: The file containing the strings to be replaced and their replacements (formatted as old_value||new_value).voiceflow.vf: The file in which the replacements will be made.docker run --rm -v $(pwd):/app schogini/replace-strings-image company.txt voiceflow.vf
To display help on how to use the script:
docker run --rm -v $(pwd):/app schogini/replace-strings-image --help
The output file will be saved as:
out-company-voiceflow.vf
replace_strings.py: The Python script that handles the string replacement.Dockerfile: The Dockerfile that builds the image using the Python 3.9 slim base image.This Docker image was created by Schogini Systems Private Limited. We specialize in AI Chatbot and Automation solutions for small businesses.
For more information about our services, visit: https://www.schogini.com.
This project is licensed under the MIT License.
Content type
Image
Digest
sha256:778ca6bd3…
Size
45 MB
Last updated
almost 2 years ago
docker pull schogini/replace-strings-image