domenic
domenic

Reputation: 9

bash command sed is outputting an unexpected error

I'm trying replace a word in a file using sed. In the same bash script I use the command :

sed -i "s/${list[$index]}/${phone}/g" $1

And it's working flawlessly on the first function, but the second function I wrote:

sed -i "s/${list[$index]}/${zipcode}/g" $1

Outputs this error:

sed: -e expression #1, char 0: no previous regular expression

I'm really desperate, I'm pretty sure that it's a dumb mistake I'm doing but I can't sort it out

Upvotes: 0

Views: 92

Answers (1)

agc
agc

Reputation: 8406

When the first half of a sed substitute command is empty:

sed 's//foo/' <<< bar

It returns this error:

sed: -e expression #1, char 0: no previous regular expression

Therefore, as William Pursell commented, there's a value of the ${list[@]} array that's empty, or maybe $index is out of the array's range.

Upvotes: 1

Related Questions