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

new=05
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

1
Cyrus On Best Solutions

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

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

Output:

DISK: [42/08]

See: The Stack Overflow Regular Expressions FAQ