Apply a vim command on several files with sed command [duplicate]
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
This question already has an answer here:
Remove carriage return in Unix
17 answers
Are shell scripts sensitive to encoding and line endings?
5 answers
I have files with the ^M
character in the vim editor. To delete that character I'm using :%s/r/r/g
based on this post: https://stackoverflow.com/a/12614243/9759150 (Question: How to convert the ^M linebreak to 'normal' linebreak in a file opened in vim?), and it works!
But doing this file by file is a tedious task, so I would like to do with a command, and I thought in the sed
command.
I have tried the following:
sed -i '%s/r/r/g' *
But I got sed: -e expression #1, char 1: unknown command:
%'`
Then, I have tried this:
sed -i 's/r/r/g' *
and I got no errors but when I open the files with vim I see the ^M
characters.
Edit with an example:
The related post for a "possible duplicate question" (Remove carriage return in Unix) removes the r
but I need to keep it. The only thing I need to change is the ^M
character for a r
one.
The original file is:
When I open vim and use :%s/r/r/g
, the result is the desired:
But with the sed -i 's/r/r/g' *
command, has not effect and the result is like the first image.
And using sed -i 's/r//g' *
(from https://stackoverflow.com/a/41461947/9759150) the result is:
It can be seen that it does remove the ^M
characters but I cannot get the same result as in vim.
bash vim sed
marked as duplicate by Benjamin W., Cyrus
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();
}
);
});
});
Nov 23 '18 at 19:32
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:
Remove carriage return in Unix
17 answers
Are shell scripts sensitive to encoding and line endings?
5 answers
I have files with the ^M
character in the vim editor. To delete that character I'm using :%s/r/r/g
based on this post: https://stackoverflow.com/a/12614243/9759150 (Question: How to convert the ^M linebreak to 'normal' linebreak in a file opened in vim?), and it works!
But doing this file by file is a tedious task, so I would like to do with a command, and I thought in the sed
command.
I have tried the following:
sed -i '%s/r/r/g' *
But I got sed: -e expression #1, char 1: unknown command:
%'`
Then, I have tried this:
sed -i 's/r/r/g' *
and I got no errors but when I open the files with vim I see the ^M
characters.
Edit with an example:
The related post for a "possible duplicate question" (Remove carriage return in Unix) removes the r
but I need to keep it. The only thing I need to change is the ^M
character for a r
one.
The original file is:
When I open vim and use :%s/r/r/g
, the result is the desired:
But with the sed -i 's/r/r/g' *
command, has not effect and the result is like the first image.
And using sed -i 's/r//g' *
(from https://stackoverflow.com/a/41461947/9759150) the result is:
It can be seen that it does remove the ^M
characters but I cannot get the same result as in vim.
bash vim sed
marked as duplicate by Benjamin W., Cyrus
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();
}
);
});
});
Nov 23 '18 at 19:32
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.
%
is vim (more precisely, ed/ex) specific: "all lines". Sed defaults to operating on all lines, so you don't need%
there. For everything else, see the linked duplicate.
– Benjamin W.
Nov 23 '18 at 19:09
sed -i 's/r//g' *
– Cyrus
Nov 23 '18 at 19:31
2
Trysed -i 's/r/n/g' *
.
– Cyrus
Nov 24 '18 at 9:08
add a comment |
This question already has an answer here:
Remove carriage return in Unix
17 answers
Are shell scripts sensitive to encoding and line endings?
5 answers
I have files with the ^M
character in the vim editor. To delete that character I'm using :%s/r/r/g
based on this post: https://stackoverflow.com/a/12614243/9759150 (Question: How to convert the ^M linebreak to 'normal' linebreak in a file opened in vim?), and it works!
But doing this file by file is a tedious task, so I would like to do with a command, and I thought in the sed
command.
I have tried the following:
sed -i '%s/r/r/g' *
But I got sed: -e expression #1, char 1: unknown command:
%'`
Then, I have tried this:
sed -i 's/r/r/g' *
and I got no errors but when I open the files with vim I see the ^M
characters.
Edit with an example:
The related post for a "possible duplicate question" (Remove carriage return in Unix) removes the r
but I need to keep it. The only thing I need to change is the ^M
character for a r
one.
The original file is:
When I open vim and use :%s/r/r/g
, the result is the desired:
But with the sed -i 's/r/r/g' *
command, has not effect and the result is like the first image.
And using sed -i 's/r//g' *
(from https://stackoverflow.com/a/41461947/9759150) the result is:
It can be seen that it does remove the ^M
characters but I cannot get the same result as in vim.
bash vim sed
This question already has an answer here:
Remove carriage return in Unix
17 answers
Are shell scripts sensitive to encoding and line endings?
5 answers
I have files with the ^M
character in the vim editor. To delete that character I'm using :%s/r/r/g
based on this post: https://stackoverflow.com/a/12614243/9759150 (Question: How to convert the ^M linebreak to 'normal' linebreak in a file opened in vim?), and it works!
But doing this file by file is a tedious task, so I would like to do with a command, and I thought in the sed
command.
I have tried the following:
sed -i '%s/r/r/g' *
But I got sed: -e expression #1, char 1: unknown command:
%'`
Then, I have tried this:
sed -i 's/r/r/g' *
and I got no errors but when I open the files with vim I see the ^M
characters.
Edit with an example:
The related post for a "possible duplicate question" (Remove carriage return in Unix) removes the r
but I need to keep it. The only thing I need to change is the ^M
character for a r
one.
The original file is:
When I open vim and use :%s/r/r/g
, the result is the desired:
But with the sed -i 's/r/r/g' *
command, has not effect and the result is like the first image.
And using sed -i 's/r//g' *
(from https://stackoverflow.com/a/41461947/9759150) the result is:
It can be seen that it does remove the ^M
characters but I cannot get the same result as in vim.
This question already has an answer here:
Remove carriage return in Unix
17 answers
Are shell scripts sensitive to encoding and line endings?
5 answers
bash vim sed
bash vim sed
edited Nov 23 '18 at 19:39
diens
asked Nov 23 '18 at 19:05
diensdiens
33913
33913
marked as duplicate by Benjamin W., Cyrus
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();
}
);
});
});
Nov 23 '18 at 19:32
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 Benjamin W., Cyrus
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();
}
);
});
});
Nov 23 '18 at 19:32
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.
%
is vim (more precisely, ed/ex) specific: "all lines". Sed defaults to operating on all lines, so you don't need%
there. For everything else, see the linked duplicate.
– Benjamin W.
Nov 23 '18 at 19:09
sed -i 's/r//g' *
– Cyrus
Nov 23 '18 at 19:31
2
Trysed -i 's/r/n/g' *
.
– Cyrus
Nov 24 '18 at 9:08
add a comment |
%
is vim (more precisely, ed/ex) specific: "all lines". Sed defaults to operating on all lines, so you don't need%
there. For everything else, see the linked duplicate.
– Benjamin W.
Nov 23 '18 at 19:09
sed -i 's/r//g' *
– Cyrus
Nov 23 '18 at 19:31
2
Trysed -i 's/r/n/g' *
.
– Cyrus
Nov 24 '18 at 9:08
%
is vim (more precisely, ed/ex) specific: "all lines". Sed defaults to operating on all lines, so you don't need %
there. For everything else, see the linked duplicate.– Benjamin W.
Nov 23 '18 at 19:09
%
is vim (more precisely, ed/ex) specific: "all lines". Sed defaults to operating on all lines, so you don't need %
there. For everything else, see the linked duplicate.– Benjamin W.
Nov 23 '18 at 19:09
sed -i 's/r//g' *
– Cyrus
Nov 23 '18 at 19:31
sed -i 's/r//g' *
– Cyrus
Nov 23 '18 at 19:31
2
2
Try
sed -i 's/r/n/g' *
.– Cyrus
Nov 24 '18 at 9:08
Try
sed -i 's/r/n/g' *
.– Cyrus
Nov 24 '18 at 9:08
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
%
is vim (more precisely, ed/ex) specific: "all lines". Sed defaults to operating on all lines, so you don't need%
there. For everything else, see the linked duplicate.– Benjamin W.
Nov 23 '18 at 19:09
sed -i 's/r//g' *
– Cyrus
Nov 23 '18 at 19:31
2
Try
sed -i 's/r/n/g' *
.– Cyrus
Nov 24 '18 at 9:08