Bash variables in sed including an end of line condition
Clash 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.
shell sed
 |Â
show 3 more comments
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.
shell sed
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 theg
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 abovesed
command? maybe you forgot to tellsed
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
 |Â
show 3 more comments
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.
shell sed
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.
shell sed
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 theg
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 abovesed
command? maybe you forgot to tellsed
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
 |Â
show 3 more comments
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 theg
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 abovesed
command? maybe you forgot to tellsed
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
 |Â
show 3 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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 tellsed
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