-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/perl | ||
# Replace a specific string in a file with a placeholder value | ||
# work with any string, including special characters | ||
|
||
use strict; | ||
use warnings; | ||
|
||
# Check if both arguments are provided | ||
if (@ARGV != 2) { | ||
die "Usage: perl replace_string.pl <string_to_replace> <file>\n"; | ||
} | ||
|
||
my $string_to_replace = $ARGV[0]; | ||
my $file = $ARGV[1]; | ||
|
||
# Read the file content | ||
open(my $fh, '<', $file) or die "Could not open file '$file' $!"; | ||
my $content = do { local $/; <$fh> }; | ||
close($fh); | ||
|
||
# Replace the string | ||
$content =~ s/\Q$string_to_replace\E/REDACTED/g; | ||
|
||
# Write the updated content back to the file | ||
open($fh, '>', $file) or die "Could not open file '$file' $!"; | ||
print $fh $content; | ||
close($fh); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters