Files
subst/README.md

85 lines
2.4 KiB
Markdown
Raw Normal View History

2025-12-15 21:31:03 +01:00
[![status-badge](https://ci.codeberg.org/api/badges/15768/status.svg)](https://ci.codeberg.org/repos/15768)
## subst - commandline tool to replace file contents or file names
2024-01-03 10:49:02 +01:00
2025-12-15 21:31:42 +01:00
> [!CAUTION]
> This software is now being maintained on [Codeberg](https://codeberg.org/scip/subst/).
2024-01-03 10:49:02 +01:00
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.
2025-12-15 21:31:03 +01:00
## Usage
2024-01-03 10:49:02 +01:00
Usage: subst [-M <perl module>] [-t] -r 's/old/new/<flags>' [ -r '...', ...] [<file> ... | /regex/]
subst [-M <perl module>] [-tR] -m 's/old/new/<flags>' [ -m '...', ...] [<file|dir> ... | /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})#<a href="$a">link</a>#g' somefile
If <file> 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.
2025-12-15 21:31:03 +01:00
## Samples
2024-01-03 10:49:02 +01:00
replace "tom" with "mac" in all *.txt files:
2025-12-15 21:31:03 +01:00
subst -r 's/tom/mac/g' *.txt
2024-01-03 10:49:02 +01:00
rename all jpg files containing whitespaces:
2025-12-15 21:31:03 +01:00
subst -m 's/ /_/g' '/.jpg/'
2024-01-03 10:49:02 +01:00
decode base64 encoded contents
2025-12-15 21:31:03 +01:00
subst -M MIME::Base64 -r 's/([a-zA-Z0-9]*)$/decode_base64($1)/gem' somefile
2024-01-03 10:49:02 +01:00
turn every uri into a link
2025-12-15 21:31:03 +01:00
subst -M "Regexp::Common qw /URI/" -r 's#($RE{URI}{HTTP})#<a href="$a">link</a>#g' somefile
2024-01-03 10:49:02 +01:00
2025-12-15 21:31:03 +01:00
## DEPENDENCIES
2024-01-03 10:51:13 +01:00
2025-12-15 21:31:03 +01:00
`subst` is a perl script and as such needs perl.
2024-01-03 10:51:13 +01:00
2025-12-15 21:31:03 +01:00
## Installation
2024-01-03 10:49:02 +01:00
2025-12-15 21:31:03 +01:00
Copy [subst](subst) to `$HOME/bin/subst`, that's all.
2024-01-03 10:49:02 +01:00
No additional perl modules are required.
2025-12-15 21:31:03 +01:00
## Copyleft and License
Copyright (c) 2002-2025 - T.v. Dein
This software is licensed under the GNU GENERAL PUBLIC LICENSE version 3.
## Authors
T.v.Dein <tom AT vondein DOT org>
## Project homepage
2024-01-03 10:49:02 +01:00
2025-12-15 21:31:03 +01:00
https://codeberg.org/scip/subst
2024-01-03 10:49:02 +01:00