╔═╗┬ ┬┌─┐┌┐┌┌─┐┌─┐┬┌┬┐
║ ├─┤├─┤││││ ┬├┤ │ │
╚═╝┴ ┴┴ ┴┘└┘└─┘└─┘o ┴
This script allows you to modify the content of a text file by adding text at the beginning or end of each line, replacing certain text, and saving the results to an output file. The script also supports the option to create a backup of the output file if one already exists.
-
Donwload the Script:
Use one of the following commands to download the script:
wget https://raw.githubusercontent.com/anyrta7/Changeit/main/changeit.sh
or use the curl
curl -O https://raw.githubusercontent.com/anyrta7/Changeit/main/changeit.sh
-
Make the Script Executable:
Grant execute permissions to the script with the following command:
chmod +x changeit.sh
To make the script run via bin, do the following:
mv changeit.sh /usr/bin/changeit
To use the script, run it with the input file and desired options. The script will process text based on the provided options.
changeit <file> [options]-h,--helpDisplay this help message-v,--verboseDisplay additional processing information-q,--quietSilent mode, no output to the screen-af,--add-firstAdd text at the beginning of each line-ae,--add-endAdd text at the end of each line-s,--selectText to be replaced (must not be empty)-r,--replaceReplacement text (must follow --select and not be empty)-o,--outputOutput file to save changes (default: display on screen)-b,--backupCreate a backup of the output file if it already exists
-
Add Text to the Beginning and End of Each Line:
changeit input.txt -af 'https://' -ae '/path' --output output.txt
-
Replace Text with Backup:
changeit input1.txt -s 'old_text' -r 'new_text' -o output.txt -b
-
Use the Script with stdin and Remove Text:
cat input.txt | changeit -s 'foo' -r ''
- If no
--outputoption is provided, the script will overwrite the original input files. - The
--updateoption will pull the latest version of the script from GitHub. Ensure thatgit,curl, orwgetis available for updating the script.
For additional help or information, refer to the help message using -h or --help.