replace with special characters

Asked by At

I have this in file.txt: DISK: [01/08], I want to replace the 01 with another variable. I want it with wildcard because there are always other numbers

sed -i "s/DISK: [**/08]/DISK: [$new/08]/" file.txt

error is this

sed: -e expression #1, char 29: unknown option to `s'

1 Answers

Cyrus On Best Solutions

Replace the first digit and the following digits with the new number from the variable.

sed 's/[0-9]\+/'"$new"'/' file


DISK: [42/08]

See: The Stack Overflow Regular Expressions FAQ