0

someString | sed 's/.//1' this line works and delete the first character

someString | sed 's/.//$j' but when I try to loop and use the index no, it does not work.

upperKeyword="secret"
for (( i=0; i<$index; i++ ))
do
    for (( j=i+1; j<$index; j++ ))
    do

        x=${upperKeyword:$i:1}
        y=${upperKeyword:$j:1}

        if [ "$x" == "$y" ]
        then
            upperKeyword=`echo $upperKeyword | sed 's/.//$j'`
            break
        fi
    done
done

echo $upperKeyword

Please help

flowr123
  • 9
  • 3
  • The single quotes will prevent the expansion of `$j`, use "double quotes" instead. This isn't an answer because you don't show where `$j` comes from. – cdarke Jan 12 '20 at 16:40
  • @flowr123 edit your post with the additional information, and ask your question in the question body too. And do not post a screenshot – Jaffa Jan 12 '20 at 16:46
  • alright, i am new here. sorry – flowr123 Jan 12 '20 at 16:48
  • Copy/paste your actual code into the body of your Q. Images are hard to read, can't be searched with the browser and can't be copy/pasted into readers terminals for testing. Use the `{}` tool from the Edit menu on mouse-selected text to format as `code/data/requiredOutput/ExactErrMsgs`. Good luck. – shellter Jan 12 '20 at 16:48
  • @kvantour thanks a lot to see an example. it helps – flowr123 Jan 12 '20 at 16:57
  • pluse-uno for improving your Q. Glad you have a solution. A good Q will include sample input, required output from that same input, current output and exact error messages and your best attempt to code a solution. Good luck! – shellter Jan 12 '20 at 17:08

0 Answers0