Reputation: 103
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
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