https://github.com/tlinden/subst
https://github.com/tlinden/subst
command-line-tool files perl regex rename rename-files rename-script replace-text replacer utitlity
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/tlinden/subst
- Owner: TLINDEN
- License: gpl-3.0
- Created: 2024-01-03T08:56:02.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-03T09:51:21.000Z (over 1 year ago)
- Last Synced: 2025-01-11T11:41:51.372Z (4 months ago)
- Topics: command-line-tool, files, perl, regex, rename, rename-files, rename-script, replace-text, replacer, utitlity
- Language: Perl
- Homepage: https://www.daemon.de/projects/scripts/subst/
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.pod
- License: LICENSE
Awesome Lists containing this project
README
=head4 subst - commandline tool to replace file contents or file names
This script can be used to replace something in a file or filename by using perl
regular expressions. It can also be used to rename files based on regexes.=head4 Usage
Usage: subst [-M ] [-t] -r 's/old/new/' [ -r '...', ...] [ ... | /regex/]
subst [-M ] [-tR] -m 's/old/new/' [ -m '...', ...] [ ... | /regex/]
Options:
-r replace contents of file(s)
-m rename file(s)
-R recursive (only used in conjunction with -m)
-M load additional perl module to enhance /e functionality.
-t test mode, do not overwrite file(s)
Samples:
- replace "tom" with "mac" in all *.txt files:
subst -r 's/tom/mac/g' *.txt
- rename all jpg files containing whitespaces:
subst -m 's/ /_/g' '/.jpg/'
- decode base64 encoded contents
subst -M MIME::Base64 -r 's/([a-zA-Z0-9]*)$/decode_base64($1)/gem' somefile
- turn every uri into a link
subst -M "Regexp::Common qw /URI/" -r 's#($RE{URI}{HTTP})#link#g' somefile
If is -, STDIN will be used as input file, results will be printed
to STDOUT. -t does not apply for STDIN input.
Substitution regex must be perlish. See 'perldoc perlre' for details.=head4 Samples
replace "tom" with "mac" in all *.txt files:
subst -r 's/tom/mac/g' *.txt
rename all jpg files containing whitespaces:
subst -m 's/ /_/g' '/.jpg/'
decode base64 encoded contents
subst -M MIME::Base64 -r 's/([a-zA-Z0-9]*)$/decode_base64($1)/gem' somefile
turn every uri into a link
subst -M "Regexp::Common qw /URI/" -r 's#($RE{URI}{HTTP})#link#g' somefile
=head4 DEPENDENCIES
B is a perl script and as such needs perl.
=head4 Installation
Copy L to B<$HOME/bin/subst>, that's all.
No additional perl modules are required.=head4 Version
1.1.5.
Copyright (c) 2002-2021 - T.v. Dein
=cut