Search and replace a pattern containing backslashes
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
2
down vote
favorite
I have a file
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180215
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
I need to search for newcommanddatestamp
and want to replace a nearby pattern with a new pattern.
Required output file
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180218
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
The backslashes are complicating this task. How do I manage?
command-line text-processing latex
add a comment |Â
up vote
2
down vote
favorite
I have a file
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180215
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
I need to search for newcommanddatestamp
and want to replace a nearby pattern with a new pattern.
Required output file
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180218
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
The backslashes are complicating this task. How do I manage?
command-line text-processing latex
4
the dupe target doesn't make sense.sed
is not a shell and the backslashes are not in filenames
â Zanna
Mar 11 at 16:19
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have a file
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180215
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
I need to search for newcommanddatestamp
and want to replace a nearby pattern with a new pattern.
Required output file
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180218
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
The backslashes are complicating this task. How do I manage?
command-line text-processing latex
I have a file
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180215
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
I need to search for newcommanddatestamp
and want to replace a nearby pattern with a new pattern.
Required output file
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180218
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
The backslashes are complicating this task. How do I manage?
command-line text-processing latex
command-line text-processing latex
edited Mar 11 at 19:34
![](https://i.stack.imgur.com/E0SEH.png?s=32&g=1)
![](https://i.stack.imgur.com/E0SEH.png?s=32&g=1)
David Foerster
26.4k1362106
26.4k1362106
asked Mar 9 at 14:33
user3708021
232
232
4
the dupe target doesn't make sense.sed
is not a shell and the backslashes are not in filenames
â Zanna
Mar 11 at 16:19
add a comment |Â
4
the dupe target doesn't make sense.sed
is not a shell and the backslashes are not in filenames
â Zanna
Mar 11 at 16:19
4
4
the dupe target doesn't make sense.
sed
is not a shell and the backslashes are not in filenamesâ Zanna
Mar 11 at 16:19
the dupe target doesn't make sense.
sed
is not a shell and the backslashes are not in filenamesâ Zanna
Mar 11 at 16:19
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
6
down vote
accepted
You likely just need to escape the backslashes i.e. \
Ex.
$ sed '/\newcommand\datestamp/ s/20180215/20180218/' file
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180218
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
accepted
You likely just need to escape the backslashes i.e. \
Ex.
$ sed '/\newcommand\datestamp/ s/20180215/20180218/' file
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180218
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
add a comment |Â
up vote
6
down vote
accepted
You likely just need to escape the backslashes i.e. \
Ex.
$ sed '/\newcommand\datestamp/ s/20180215/20180218/' file
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180218
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
add a comment |Â
up vote
6
down vote
accepted
up vote
6
down vote
accepted
You likely just need to escape the backslashes i.e. \
Ex.
$ sed '/\newcommand\datestamp/ s/20180215/20180218/' file
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180218
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
You likely just need to escape the backslashes i.e. \
Ex.
$ sed '/\newcommand\datestamp/ s/20180215/20180218/' file
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
newcommanddatestamp20180218
bla bla bla bla bla bla bla
bla bla bla bla bla bla bla
answered Mar 9 at 14:36
steeldriver
63.2k1198167
63.2k1198167
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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%2faskubuntu.com%2fquestions%2f1013419%2fsearch-and-replace-a-pattern-containing-backslashes%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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
4
the dupe target doesn't make sense.
sed
is not a shell and the backslashes are not in filenamesâ Zanna
Mar 11 at 16:19