using sed replace the new line with character
I am using sed
to remove the new line and replace with <br>
but I am not able to get the desired output.
I wrote:
find . -name $1 -print0 | xargs -0 sed -i '' -e 's|n|ABC|g'
...but this doesn't work.
scripts sed text-processing
add a comment |
I am using sed
to remove the new line and replace with <br>
but I am not able to get the desired output.
I wrote:
find . -name $1 -print0 | xargs -0 sed -i '' -e 's|n|ABC|g'
...but this doesn't work.
scripts sed text-processing
possible duplicate of Find and replace text within a file using commands
– Pandya
Sep 26 '14 at 16:01
You can invoke programs onfind
results a bit more elegantly with the-exec
action:find . -name $1 -exec sed -i '' -e 's|n|ABC|g' {} +
– David Foerster
Sep 26 '14 at 16:12
@Pandya I don't believe this is a duplicate, the OP is already using what that question would suggest, he just needs help getting the exact command for his specific environment correct, which that question won't provide.
– Seth♦
Sep 26 '14 at 16:19
1
You can usetr 'n' '<br>' < file
– Pandya
Sep 27 '14 at 2:14
add a comment |
I am using sed
to remove the new line and replace with <br>
but I am not able to get the desired output.
I wrote:
find . -name $1 -print0 | xargs -0 sed -i '' -e 's|n|ABC|g'
...but this doesn't work.
scripts sed text-processing
I am using sed
to remove the new line and replace with <br>
but I am not able to get the desired output.
I wrote:
find . -name $1 -print0 | xargs -0 sed -i '' -e 's|n|ABC|g'
...but this doesn't work.
scripts sed text-processing
scripts sed text-processing
edited Dec 25 '18 at 9:27
agc
1409
1409
asked Sep 26 '14 at 14:21
abhijeetmoteabhijeetmote
236
236
possible duplicate of Find and replace text within a file using commands
– Pandya
Sep 26 '14 at 16:01
You can invoke programs onfind
results a bit more elegantly with the-exec
action:find . -name $1 -exec sed -i '' -e 's|n|ABC|g' {} +
– David Foerster
Sep 26 '14 at 16:12
@Pandya I don't believe this is a duplicate, the OP is already using what that question would suggest, he just needs help getting the exact command for his specific environment correct, which that question won't provide.
– Seth♦
Sep 26 '14 at 16:19
1
You can usetr 'n' '<br>' < file
– Pandya
Sep 27 '14 at 2:14
add a comment |
possible duplicate of Find and replace text within a file using commands
– Pandya
Sep 26 '14 at 16:01
You can invoke programs onfind
results a bit more elegantly with the-exec
action:find . -name $1 -exec sed -i '' -e 's|n|ABC|g' {} +
– David Foerster
Sep 26 '14 at 16:12
@Pandya I don't believe this is a duplicate, the OP is already using what that question would suggest, he just needs help getting the exact command for his specific environment correct, which that question won't provide.
– Seth♦
Sep 26 '14 at 16:19
1
You can usetr 'n' '<br>' < file
– Pandya
Sep 27 '14 at 2:14
possible duplicate of Find and replace text within a file using commands
– Pandya
Sep 26 '14 at 16:01
possible duplicate of Find and replace text within a file using commands
– Pandya
Sep 26 '14 at 16:01
You can invoke programs on
find
results a bit more elegantly with the -exec
action: find . -name $1 -exec sed -i '' -e 's|n|ABC|g' {} +
– David Foerster
Sep 26 '14 at 16:12
You can invoke programs on
find
results a bit more elegantly with the -exec
action: find . -name $1 -exec sed -i '' -e 's|n|ABC|g' {} +
– David Foerster
Sep 26 '14 at 16:12
@Pandya I don't believe this is a duplicate, the OP is already using what that question would suggest, he just needs help getting the exact command for his specific environment correct, which that question won't provide.
– Seth♦
Sep 26 '14 at 16:19
@Pandya I don't believe this is a duplicate, the OP is already using what that question would suggest, he just needs help getting the exact command for his specific environment correct, which that question won't provide.
– Seth♦
Sep 26 '14 at 16:19
1
1
You can use
tr 'n' '<br>' < file
– Pandya
Sep 27 '14 at 2:14
You can use
tr 'n' '<br>' < file
– Pandya
Sep 27 '14 at 2:14
add a comment |
4 Answers
4
active
oldest
votes
Your sed expression is treating each line separately - so it doesn't actually read the newline character into the pattern buffer and hence can't replace it. If you just want to add <br>
while retaining the actual newline as well, you can just use the end-of-line marker $
and do
sed -i'' 's|$|<br>|' file
Note that the empty backup file name - if you use it - must directly follow the -i
like -i''
; also the -e
is not necessary when using a single expression.
OTOH if you really want to replace actual newline characters, you need to jump through some extra hoops, for example
sed -i'' -e :a -e '$!N;s/n/<br>/;ta' -e 'P;D' file
or, more compactly
sed -i'' ':a; $!N; s|n|<br>|; ta; P;D' file
which read successive pairs of lines into the pattern buffer and then replace the intervening newline - see Famous Sed One-Liners Explained.
add a comment |
If you want to replace the new line and with <br>
, you can use
find . -name $1 -print0 | xargs -0 sed -i 's/.*$/&<br>/'
add a comment |
Why not just
find . -name $1 | xargs sed -ri "s/$/<br>/"
?
(Try without the i
, first ;-) )
add a comment |
To replace inline n
with <br>
, just use perl (or sed), needless to call find
for that task:
perl -pi -e "s/$/<br>/" myfile
Or for an alias:
alias brtag='perl -pi -e "s/$/<br>/" $1'
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f528878%2fusing-sed-replace-the-new-line-with-character%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your sed expression is treating each line separately - so it doesn't actually read the newline character into the pattern buffer and hence can't replace it. If you just want to add <br>
while retaining the actual newline as well, you can just use the end-of-line marker $
and do
sed -i'' 's|$|<br>|' file
Note that the empty backup file name - if you use it - must directly follow the -i
like -i''
; also the -e
is not necessary when using a single expression.
OTOH if you really want to replace actual newline characters, you need to jump through some extra hoops, for example
sed -i'' -e :a -e '$!N;s/n/<br>/;ta' -e 'P;D' file
or, more compactly
sed -i'' ':a; $!N; s|n|<br>|; ta; P;D' file
which read successive pairs of lines into the pattern buffer and then replace the intervening newline - see Famous Sed One-Liners Explained.
add a comment |
Your sed expression is treating each line separately - so it doesn't actually read the newline character into the pattern buffer and hence can't replace it. If you just want to add <br>
while retaining the actual newline as well, you can just use the end-of-line marker $
and do
sed -i'' 's|$|<br>|' file
Note that the empty backup file name - if you use it - must directly follow the -i
like -i''
; also the -e
is not necessary when using a single expression.
OTOH if you really want to replace actual newline characters, you need to jump through some extra hoops, for example
sed -i'' -e :a -e '$!N;s/n/<br>/;ta' -e 'P;D' file
or, more compactly
sed -i'' ':a; $!N; s|n|<br>|; ta; P;D' file
which read successive pairs of lines into the pattern buffer and then replace the intervening newline - see Famous Sed One-Liners Explained.
add a comment |
Your sed expression is treating each line separately - so it doesn't actually read the newline character into the pattern buffer and hence can't replace it. If you just want to add <br>
while retaining the actual newline as well, you can just use the end-of-line marker $
and do
sed -i'' 's|$|<br>|' file
Note that the empty backup file name - if you use it - must directly follow the -i
like -i''
; also the -e
is not necessary when using a single expression.
OTOH if you really want to replace actual newline characters, you need to jump through some extra hoops, for example
sed -i'' -e :a -e '$!N;s/n/<br>/;ta' -e 'P;D' file
or, more compactly
sed -i'' ':a; $!N; s|n|<br>|; ta; P;D' file
which read successive pairs of lines into the pattern buffer and then replace the intervening newline - see Famous Sed One-Liners Explained.
Your sed expression is treating each line separately - so it doesn't actually read the newline character into the pattern buffer and hence can't replace it. If you just want to add <br>
while retaining the actual newline as well, you can just use the end-of-line marker $
and do
sed -i'' 's|$|<br>|' file
Note that the empty backup file name - if you use it - must directly follow the -i
like -i''
; also the -e
is not necessary when using a single expression.
OTOH if you really want to replace actual newline characters, you need to jump through some extra hoops, for example
sed -i'' -e :a -e '$!N;s/n/<br>/;ta' -e 'P;D' file
or, more compactly
sed -i'' ':a; $!N; s|n|<br>|; ta; P;D' file
which read successive pairs of lines into the pattern buffer and then replace the intervening newline - see Famous Sed One-Liners Explained.
answered Sep 26 '14 at 14:57
steeldriversteeldriver
66k11105178
66k11105178
add a comment |
add a comment |
If you want to replace the new line and with <br>
, you can use
find . -name $1 -print0 | xargs -0 sed -i 's/.*$/&<br>/'
add a comment |
If you want to replace the new line and with <br>
, you can use
find . -name $1 -print0 | xargs -0 sed -i 's/.*$/&<br>/'
add a comment |
If you want to replace the new line and with <br>
, you can use
find . -name $1 -print0 | xargs -0 sed -i 's/.*$/&<br>/'
If you want to replace the new line and with <br>
, you can use
find . -name $1 -print0 | xargs -0 sed -i 's/.*$/&<br>/'
answered Sep 26 '14 at 14:42
g_pg_p
12.5k24461
12.5k24461
add a comment |
add a comment |
Why not just
find . -name $1 | xargs sed -ri "s/$/<br>/"
?
(Try without the i
, first ;-) )
add a comment |
Why not just
find . -name $1 | xargs sed -ri "s/$/<br>/"
?
(Try without the i
, first ;-) )
add a comment |
Why not just
find . -name $1 | xargs sed -ri "s/$/<br>/"
?
(Try without the i
, first ;-) )
Why not just
find . -name $1 | xargs sed -ri "s/$/<br>/"
?
(Try without the i
, first ;-) )
answered Sep 26 '14 at 14:44
laruisslaruiss
1112
1112
add a comment |
add a comment |
To replace inline n
with <br>
, just use perl (or sed), needless to call find
for that task:
perl -pi -e "s/$/<br>/" myfile
Or for an alias:
alias brtag='perl -pi -e "s/$/<br>/" $1'
add a comment |
To replace inline n
with <br>
, just use perl (or sed), needless to call find
for that task:
perl -pi -e "s/$/<br>/" myfile
Or for an alias:
alias brtag='perl -pi -e "s/$/<br>/" $1'
add a comment |
To replace inline n
with <br>
, just use perl (or sed), needless to call find
for that task:
perl -pi -e "s/$/<br>/" myfile
Or for an alias:
alias brtag='perl -pi -e "s/$/<br>/" $1'
To replace inline n
with <br>
, just use perl (or sed), needless to call find
for that task:
perl -pi -e "s/$/<br>/" myfile
Or for an alias:
alias brtag='perl -pi -e "s/$/<br>/" $1'
answered Sep 26 '14 at 14:53
Sylvain PineauSylvain Pineau
48.4k16104149
48.4k16104149
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f528878%2fusing-sed-replace-the-new-line-with-character%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
possible duplicate of Find and replace text within a file using commands
– Pandya
Sep 26 '14 at 16:01
You can invoke programs on
find
results a bit more elegantly with the-exec
action:find . -name $1 -exec sed -i '' -e 's|n|ABC|g' {} +
– David Foerster
Sep 26 '14 at 16:12
@Pandya I don't believe this is a duplicate, the OP is already using what that question would suggest, he just needs help getting the exact command for his specific environment correct, which that question won't provide.
– Seth♦
Sep 26 '14 at 16:19
1
You can use
tr 'n' '<br>' < file
– Pandya
Sep 27 '14 at 2:14