I am trying to remove the first n characters from a stringI get the following error :line 5: ${ echo $data | sed -r 's/.{ $index0 }//' }: bad substitutionwhen using this code from within a bash script :data=${ echo $data | sed -r 's/.{$index}//' }any correction please ?
sed substitution with a variable
sed;variable
Well,    Command substitution is $( ... ), not ${ ... }. Regular parenthesis, not curly braces.   You have $index within single-quotes, so it will not be expanded by the shell. You need double-quotes for that.Put double-quotes around $data in the echo, it makes a difference if data contains whitespace or glob charactersIn bash, you can just use  the substring expansion data=${data:$index} to drop a number of characters from the front of the string.Suggested reading: http://mywiki.wooledge.org/BashGuide