Use variable inside sed command [duplicate]
This question already has an answer here:
How can I use variables in the LHS and RHS of a sed substitution?
11 answers
How to use variables in sed command
1 answer
how can i use variables inside this sed command?
sed -i.bak -e '/triggerword/,${w $DIR/tempfile' -e 'd;}' $DIR/targetfile
inside -e '{w $DIR/tempfile' -e 'd;}'
the $DIR/tempfile
isn't recognized
sed variable-substitution
marked as duplicate by steeldriver, Kusalananda♦
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Mar 7 at 11:01
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How can I use variables in the LHS and RHS of a sed substitution?
11 answers
How to use variables in sed command
1 answer
how can i use variables inside this sed command?
sed -i.bak -e '/triggerword/,${w $DIR/tempfile' -e 'd;}' $DIR/targetfile
inside -e '{w $DIR/tempfile' -e 'd;}'
the $DIR/tempfile
isn't recognized
sed variable-substitution
marked as duplicate by steeldriver, Kusalananda♦
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Mar 7 at 11:01
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
You need to search for shell quoting, this has been asked before. Note also you're trying to use nested single quotes, which won't work as expected (they can't be nested, so you end up with two quoted strings with text inbetween).
– wurtel
Mar 7 at 10:55
ok i don't understand. is it possible to use variables in this case or not and what would it look like?
– diggidre
Mar 7 at 11:12
@wurtel They are not using nested single quotes.
– Kusalananda♦
Mar 7 at 11:13
@diggidre As per the answers to the duplicated questions:-e "{w $DIR/tempfile" -e 'd;}'
– Kusalananda♦
Mar 7 at 11:15
OK sry i messed up a bit... next step... sed -i.bak -e '/triggerword/,$ "{w $DIR/tempfile" -e 'd;}' $DIR/sourcefile sed -n '/triggerword/,$p' $DIR/tempfile >> $DIR/targetfile sed -i 's/triggerword/#/g' $DIR/targetfile Above gives syntax error: unterminated quoted string When I use sed -i.bak -e '/triggerword/,${w /tmp/tempfile' -e 'd;}' $DIR/sourcefile works like a charm but without variable
– diggidre
Mar 7 at 11:31
add a comment |
This question already has an answer here:
How can I use variables in the LHS and RHS of a sed substitution?
11 answers
How to use variables in sed command
1 answer
how can i use variables inside this sed command?
sed -i.bak -e '/triggerword/,${w $DIR/tempfile' -e 'd;}' $DIR/targetfile
inside -e '{w $DIR/tempfile' -e 'd;}'
the $DIR/tempfile
isn't recognized
sed variable-substitution
This question already has an answer here:
How can I use variables in the LHS and RHS of a sed substitution?
11 answers
How to use variables in sed command
1 answer
how can i use variables inside this sed command?
sed -i.bak -e '/triggerword/,${w $DIR/tempfile' -e 'd;}' $DIR/targetfile
inside -e '{w $DIR/tempfile' -e 'd;}'
the $DIR/tempfile
isn't recognized
This question already has an answer here:
How can I use variables in the LHS and RHS of a sed substitution?
11 answers
How to use variables in sed command
1 answer
sed variable-substitution
sed variable-substitution
edited Mar 7 at 11:13
Kusalananda♦
139k17259429
139k17259429
asked Mar 7 at 10:49
diggidrediggidre
385
385
marked as duplicate by steeldriver, Kusalananda♦
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Mar 7 at 11:01
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by steeldriver, Kusalananda♦
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Mar 7 at 11:01
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
You need to search for shell quoting, this has been asked before. Note also you're trying to use nested single quotes, which won't work as expected (they can't be nested, so you end up with two quoted strings with text inbetween).
– wurtel
Mar 7 at 10:55
ok i don't understand. is it possible to use variables in this case or not and what would it look like?
– diggidre
Mar 7 at 11:12
@wurtel They are not using nested single quotes.
– Kusalananda♦
Mar 7 at 11:13
@diggidre As per the answers to the duplicated questions:-e "{w $DIR/tempfile" -e 'd;}'
– Kusalananda♦
Mar 7 at 11:15
OK sry i messed up a bit... next step... sed -i.bak -e '/triggerword/,$ "{w $DIR/tempfile" -e 'd;}' $DIR/sourcefile sed -n '/triggerword/,$p' $DIR/tempfile >> $DIR/targetfile sed -i 's/triggerword/#/g' $DIR/targetfile Above gives syntax error: unterminated quoted string When I use sed -i.bak -e '/triggerword/,${w /tmp/tempfile' -e 'd;}' $DIR/sourcefile works like a charm but without variable
– diggidre
Mar 7 at 11:31
add a comment |
You need to search for shell quoting, this has been asked before. Note also you're trying to use nested single quotes, which won't work as expected (they can't be nested, so you end up with two quoted strings with text inbetween).
– wurtel
Mar 7 at 10:55
ok i don't understand. is it possible to use variables in this case or not and what would it look like?
– diggidre
Mar 7 at 11:12
@wurtel They are not using nested single quotes.
– Kusalananda♦
Mar 7 at 11:13
@diggidre As per the answers to the duplicated questions:-e "{w $DIR/tempfile" -e 'd;}'
– Kusalananda♦
Mar 7 at 11:15
OK sry i messed up a bit... next step... sed -i.bak -e '/triggerword/,$ "{w $DIR/tempfile" -e 'd;}' $DIR/sourcefile sed -n '/triggerword/,$p' $DIR/tempfile >> $DIR/targetfile sed -i 's/triggerword/#/g' $DIR/targetfile Above gives syntax error: unterminated quoted string When I use sed -i.bak -e '/triggerword/,${w /tmp/tempfile' -e 'd;}' $DIR/sourcefile works like a charm but without variable
– diggidre
Mar 7 at 11:31
You need to search for shell quoting, this has been asked before. Note also you're trying to use nested single quotes, which won't work as expected (they can't be nested, so you end up with two quoted strings with text inbetween).
– wurtel
Mar 7 at 10:55
You need to search for shell quoting, this has been asked before. Note also you're trying to use nested single quotes, which won't work as expected (they can't be nested, so you end up with two quoted strings with text inbetween).
– wurtel
Mar 7 at 10:55
ok i don't understand. is it possible to use variables in this case or not and what would it look like?
– diggidre
Mar 7 at 11:12
ok i don't understand. is it possible to use variables in this case or not and what would it look like?
– diggidre
Mar 7 at 11:12
@wurtel They are not using nested single quotes.
– Kusalananda♦
Mar 7 at 11:13
@wurtel They are not using nested single quotes.
– Kusalananda♦
Mar 7 at 11:13
@diggidre As per the answers to the duplicated questions:
-e "{w $DIR/tempfile" -e 'd;}'
– Kusalananda♦
Mar 7 at 11:15
@diggidre As per the answers to the duplicated questions:
-e "{w $DIR/tempfile" -e 'd;}'
– Kusalananda♦
Mar 7 at 11:15
OK sry i messed up a bit... next step... sed -i.bak -e '/triggerword/,$ "{w $DIR/tempfile" -e 'd;}' $DIR/sourcefile sed -n '/triggerword/,$p' $DIR/tempfile >> $DIR/targetfile sed -i 's/triggerword/#/g' $DIR/targetfile Above gives syntax error: unterminated quoted string When I use sed -i.bak -e '/triggerword/,${w /tmp/tempfile' -e 'd;}' $DIR/sourcefile works like a charm but without variable
– diggidre
Mar 7 at 11:31
OK sry i messed up a bit... next step... sed -i.bak -e '/triggerword/,$ "{w $DIR/tempfile" -e 'd;}' $DIR/sourcefile sed -n '/triggerword/,$p' $DIR/tempfile >> $DIR/targetfile sed -i 's/triggerword/#/g' $DIR/targetfile Above gives syntax error: unterminated quoted string When I use sed -i.bak -e '/triggerword/,${w /tmp/tempfile' -e 'd;}' $DIR/sourcefile works like a charm but without variable
– diggidre
Mar 7 at 11:31
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to search for shell quoting, this has been asked before. Note also you're trying to use nested single quotes, which won't work as expected (they can't be nested, so you end up with two quoted strings with text inbetween).
– wurtel
Mar 7 at 10:55
ok i don't understand. is it possible to use variables in this case or not and what would it look like?
– diggidre
Mar 7 at 11:12
@wurtel They are not using nested single quotes.
– Kusalananda♦
Mar 7 at 11:13
@diggidre As per the answers to the duplicated questions:
-e "{w $DIR/tempfile" -e 'd;}'
– Kusalananda♦
Mar 7 at 11:15
OK sry i messed up a bit... next step... sed -i.bak -e '/triggerword/,$ "{w $DIR/tempfile" -e 'd;}' $DIR/sourcefile sed -n '/triggerword/,$p' $DIR/tempfile >> $DIR/targetfile sed -i 's/triggerword/#/g' $DIR/targetfile Above gives syntax error: unterminated quoted string When I use sed -i.bak -e '/triggerword/,${w /tmp/tempfile' -e 'd;}' $DIR/sourcefile works like a charm but without variable
– diggidre
Mar 7 at 11:31