0

I ned to replace the substring from shell script. Using bellow link i have try but no luck.

Replace one substring for another string in shell script

I have try:

variableString=$(find . -type f -name 'test.*.nupkg')
oldstr="./"
newstr=""
result=$(echo $variableString | sed "s/$oldstr/$newstr/g")
echo "Original String :  $variableString"
echo "Replaced String :  $result"

output:

Original String :  ./test.6.0.19.nupkg
Replaced String :  

I need to replace the ./ to ""

Excepted output:

Original String :  ./test.6.0.19.nupkg
Replaced String :  test.6.0.19.nupkg
Sujeet Singh
  • 141
  • 1
  • 3
  • The program you posted does **not** produce the output you claimed, but yields an error message. If you run your program with `set -x` turned on, you will see that the sed command expands to `sed s/.///g`, and this is of course incorrect (just count the slashes!). – user1934428 Aug 03 '22 at 08:55

1 Answers1

0

I am able to replace the first two character.

variableString=$(find . -type f -name 'test.*.nupkg')
result=${variableString:2}
echo "Original String :  $variableString"
echo "Replaced String :  $result"

output

Original String :  ./test.6.0.19.nupkg
Replaced String :  test.6.0.19.nupkg

thx

Sujeet Singh
  • 141
  • 1
  • 3