0
rated 0 times
[
0]
[
0]
/ answers: 1 / hits: 1413
/ 3 Years ago, thu, december 2, 2021, 1:52:23
I want to customize a string with * characters, except the first and last 3 characters in the string, as I don't want to print this string in logs.
For example: if the string is abctextxyz
, I want it changed to abc****xyz
I tried to print the string with * except the first and last 3 characters, but hard-coding it to a 7 letters string. I would like to customize it for an arbitrary length.
If the string is of 6 character or less, it should be printed as it is.
Here is a bash script that I have created for this purpose:
#!/bin/bash
STRING1="testabctest";
echo $STRING1;
STRING2=${STRING1:0:3};
echo $STRING2;
STRING3=${STRING1:(-3)};
echo $STRING3;
STRING4=$STRING2"****"$STRING3;
echo $STRING4
More From » command-line