0

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'

oguz ismail
  • 1
  • 16
  • 47
  • 69
Mike Shiwa
  • 71
  • 6
  • 1
    See: [Escaping forward slashes in sed command](https://stackoverflow.com/q/40714970/3776858) – Cyrus May 05 '19 at 12:43
  • 2
    Possible duplicate of [Escaping forward slashes in sed command](https://stackoverflow.com/questions/40714970/escaping-forward-slashes-in-sed-command) – tripleee May 05 '19 at 14:23
  • Possible duplicate of [Escape a string for a sed replace pattern](/questions/407523/escape-a-string-for-a-sed-replace-pattern) – tripleee May 06 '19 at 05:20

1 Answers1

1

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

Cyrus
  • 84,225
  • 14
  • 89
  • 153