Bash variables in sed including an end of line condition

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have a bash variable replacement in sed, where some information at the end of line of the 3rd line for example should also be matched.



a=3 #line no
b=tap #pattern
c=9 #replacement data
sed "$as/$b$/$c/g"


The dollar to match the end of line doesn't seem to work, the one here $b$.
The script works without the dollar



For example, in a file :



3, 7, 9
1, 3, 5
11, 23, tap


which should become 11, 23, 9, I wanted the $ to identify tap as the last object. Now, tap can be a number too, so don't specialize it to a text.







share|improve this question






















  • Can you give a specific example of it not seeming to work? afaik a double-quoted $ on its own shouldn't be subject to expansion (although you could try $ if there's doubt)
    – steeldriver
    Feb 18 at 3:35










  • in a file, have three fields: 3, 4, 5 9, 8, 7 1, 3, tap should become 6, 7, 9
    – Pgram
    Feb 18 at 3:38











  • Well aside from the g modifier not really making sense when the pattern is anchored, I don't see what the issue is here?
    – steeldriver
    Feb 18 at 3:53










  • What result is giving your above sed command? maybe you forgot to tell sed the input file it should run that replacement in?
    – Î±Ò“sнιη
    Feb 18 at 3:56











  • I've cat'ted the file before and after replacement. Nothing happens ! Do you think it has anything to do with file format ? It's a simple csv file
    – Pgram
    Feb 18 at 3:58















up vote
0
down vote

favorite












I have a bash variable replacement in sed, where some information at the end of line of the 3rd line for example should also be matched.



a=3 #line no
b=tap #pattern
c=9 #replacement data
sed "$as/$b$/$c/g"


The dollar to match the end of line doesn't seem to work, the one here $b$.
The script works without the dollar



For example, in a file :



3, 7, 9
1, 3, 5
11, 23, tap


which should become 11, 23, 9, I wanted the $ to identify tap as the last object. Now, tap can be a number too, so don't specialize it to a text.







share|improve this question






















  • Can you give a specific example of it not seeming to work? afaik a double-quoted $ on its own shouldn't be subject to expansion (although you could try $ if there's doubt)
    – steeldriver
    Feb 18 at 3:35










  • in a file, have three fields: 3, 4, 5 9, 8, 7 1, 3, tap should become 6, 7, 9
    – Pgram
    Feb 18 at 3:38











  • Well aside from the g modifier not really making sense when the pattern is anchored, I don't see what the issue is here?
    – steeldriver
    Feb 18 at 3:53










  • What result is giving your above sed command? maybe you forgot to tell sed the input file it should run that replacement in?
    – Î±Ò“sнιη
    Feb 18 at 3:56











  • I've cat'ted the file before and after replacement. Nothing happens ! Do you think it has anything to do with file format ? It's a simple csv file
    – Pgram
    Feb 18 at 3:58













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a bash variable replacement in sed, where some information at the end of line of the 3rd line for example should also be matched.



a=3 #line no
b=tap #pattern
c=9 #replacement data
sed "$as/$b$/$c/g"


The dollar to match the end of line doesn't seem to work, the one here $b$.
The script works without the dollar



For example, in a file :



3, 7, 9
1, 3, 5
11, 23, tap


which should become 11, 23, 9, I wanted the $ to identify tap as the last object. Now, tap can be a number too, so don't specialize it to a text.







share|improve this question














I have a bash variable replacement in sed, where some information at the end of line of the 3rd line for example should also be matched.



a=3 #line no
b=tap #pattern
c=9 #replacement data
sed "$as/$b$/$c/g"


The dollar to match the end of line doesn't seem to work, the one here $b$.
The script works without the dollar



For example, in a file :



3, 7, 9
1, 3, 5
11, 23, tap


which should become 11, 23, 9, I wanted the $ to identify tap as the last object. Now, tap can be a number too, so don't specialize it to a text.









share|improve this question













share|improve this question




share|improve this question








edited Feb 18 at 4:03

























asked Feb 18 at 2:58









Pgram

113




113











  • Can you give a specific example of it not seeming to work? afaik a double-quoted $ on its own shouldn't be subject to expansion (although you could try $ if there's doubt)
    – steeldriver
    Feb 18 at 3:35










  • in a file, have three fields: 3, 4, 5 9, 8, 7 1, 3, tap should become 6, 7, 9
    – Pgram
    Feb 18 at 3:38











  • Well aside from the g modifier not really making sense when the pattern is anchored, I don't see what the issue is here?
    – steeldriver
    Feb 18 at 3:53










  • What result is giving your above sed command? maybe you forgot to tell sed the input file it should run that replacement in?
    – Î±Ò“sнιη
    Feb 18 at 3:56











  • I've cat'ted the file before and after replacement. Nothing happens ! Do you think it has anything to do with file format ? It's a simple csv file
    – Pgram
    Feb 18 at 3:58

















  • Can you give a specific example of it not seeming to work? afaik a double-quoted $ on its own shouldn't be subject to expansion (although you could try $ if there's doubt)
    – steeldriver
    Feb 18 at 3:35










  • in a file, have three fields: 3, 4, 5 9, 8, 7 1, 3, tap should become 6, 7, 9
    – Pgram
    Feb 18 at 3:38











  • Well aside from the g modifier not really making sense when the pattern is anchored, I don't see what the issue is here?
    – steeldriver
    Feb 18 at 3:53










  • What result is giving your above sed command? maybe you forgot to tell sed the input file it should run that replacement in?
    – Î±Ò“sнιη
    Feb 18 at 3:56











  • I've cat'ted the file before and after replacement. Nothing happens ! Do you think it has anything to do with file format ? It's a simple csv file
    – Pgram
    Feb 18 at 3:58
















Can you give a specific example of it not seeming to work? afaik a double-quoted $ on its own shouldn't be subject to expansion (although you could try $ if there's doubt)
– steeldriver
Feb 18 at 3:35




Can you give a specific example of it not seeming to work? afaik a double-quoted $ on its own shouldn't be subject to expansion (although you could try $ if there's doubt)
– steeldriver
Feb 18 at 3:35












in a file, have three fields: 3, 4, 5 9, 8, 7 1, 3, tap should become 6, 7, 9
– Pgram
Feb 18 at 3:38





in a file, have three fields: 3, 4, 5 9, 8, 7 1, 3, tap should become 6, 7, 9
– Pgram
Feb 18 at 3:38













Well aside from the g modifier not really making sense when the pattern is anchored, I don't see what the issue is here?
– steeldriver
Feb 18 at 3:53




Well aside from the g modifier not really making sense when the pattern is anchored, I don't see what the issue is here?
– steeldriver
Feb 18 at 3:53












What result is giving your above sed command? maybe you forgot to tell sed the input file it should run that replacement in?
– Î±Ò“sнιη
Feb 18 at 3:56





What result is giving your above sed command? maybe you forgot to tell sed the input file it should run that replacement in?
– Î±Ò“sнιη
Feb 18 at 3:56













I've cat'ted the file before and after replacement. Nothing happens ! Do you think it has anything to do with file format ? It's a simple csv file
– Pgram
Feb 18 at 3:58





I've cat'ted the file before and after replacement. Nothing happens ! Do you think it has anything to do with file format ? It's a simple csv file
– Pgram
Feb 18 at 3:58
















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f424895%2fbash-variables-in-sed-including-an-end-of-line-condition%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f424895%2fbash-variables-in-sed-including-an-end-of-line-condition%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay