AP70
AP70

Reputation: 103

sed insert variable after quoted string

How do I insert a variable after a quoted string in a file using sed?

The variable: $num The quoted string: "ID": "

The output in the file would look like: "ID": "$num

Upvotes: 0

Views: 70

Answers (1)

choroba
choroba

Reputation: 241758

Use the variable in double quotes.

echo '"ID": "' | sed -e "s/^\\(\"ID\": \"\\)/\\1$num"/

Note that backslashes need to be backslashed in double quotes. Also, it will only work if $num doesn't contain special characters (e.g. slash).

Upvotes: 1

Related Questions