Hi,
I have the following string: $string= BG_1_12345_?_XX.SVF
The '?' means that any character could be in that position.
If from a file i will read the string $str=12345 how can i modify the $str in order to be $str=$string.
Best regards,
Christos
Hi,
I have the following string: $string= BG_1_12345_?_XX.SVF
The '?' means that any character could be in that position.
If from a file i will read the string $str=12345 how can i modify the $str in order to be $str=$string.
Best regards,
Christos
Clarify your question, its vague what you're trying to achief.
Regards
Hi,
try:
if [[ "$string" =~ "$str" ]] ;
then
echo $(sed "s/\(.*\)[0-9]\{5\}\(.*\)/\1${str}\2/" <<< $string );
fi
If $string contains the numbers of $str, then
use sed to read in the part in frot of the matched numbers "\1"
and the part after the matched numbers "\2",
put the content of $str between both and echo the result.
Another solution would be:
echo $(sed "s/\(.*\)${str}\(.*\)/\1${str}\2/" <<< $string )
HTH Chris
What i would like to do is from the $str string to create the $string string by appending/prepending the correct characters. The problem is with the characters ? which is a character that i do not know.
I would like to do this in perl.
Thank you
Christos
Hi,
here the same in perl:
perl -e '$string="BG_1_12345_X_XX.SVF"; $str=12345;
if ( $string =~ /(.*)$str(.*)/ ){$front=$1;$end=$2;printf "$1$str$2"}'
This assigns $string a value, $str contains a substring of $string.
Then we test if $string matches $str and save the part in front and after
$str in two variables $front and $end. Finally the concatenation of
$1$str$2 is print out.
HTH Chris