sed '5innn' myfile inserts first n as a literal n, and the other two nn as new lines, is it possible to...
Can two waves interfere head on?
Soft constraints and hard constraints
Do gauntlets count as armor?
Why do we need an estimator to be consistent?
Counting multiples of 3 up to a given number
What does a Nintendo Game Boy do when turned on without a game cartridge inserted?
How to split the polynomial .
ISCSI, multiple initiaros for the same lun
What's so great about Shalantha's Delicate Disk?
What is the intuition for higher homotopy groups not vanishing?
Quickest way to move a line in a text file before another line in a text file?
Is art a form of communication?
How to tell readers that I know my story is factually incorrect?
Where can I find standards for statistical acronyms and whether they should be capitalized or lower case?
Host telling me to cancel my booking in exchange for a discount?
What is the minimum wait before I may I re-enter the USA after a 90 day visit on the Visa B-2 Program?
How can electronics on board JWST survive the low operating temperature while it's difficult to survive lunar nights?
How does the Gameboy's memory bank switching work?
Grease/lubricate rubber stabilizer bar bushings?
Aren't all schwa sounds literally /ø/?
How to hide your own body?
Ethiopian Airlines tickets seem to always have the same price regardless of the proximity of the date?
Why didn't NASA launch communications relay satellites for the Apollo missions?
You have no, but can try for yes
sed '5innn' myfile inserts first n as a literal n, and the other two nn as new lines, is it possible to insert all 3 new lines?
sed script to insert line after the last matching line in a fileSubstituting the first occurrence of a pattern in a line, for all the lines in a file with sedRemove the exact same matching lines with sedusing sed to modify all files in a directory and name the outputs accordinglyHere tag ignoring trailing newlinesReplace values in a variable and retain new lines in BASHUsing sed to replace the hexadecimal code for URL and to insert new SVG codes after SVG tag in all SVG filesgrep everything up until and including a patternsed command to insert between two strings that are returned from another sed commandExtra Backslash Required in First Appended Newline in sed
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I'm writing a Bash script and when inserting lines to a file using GNU sed, the first new line is inserted as a literal n, while the rest is inserted as new lines. The command is this:
sed '5innn' myfile
The output is this:
n
As seen, the first line in the output contains an "n" where it should be none, what am I missing about this behavior? is it possible to make sed insert only new lines with 'n'? Thank you.
bash sed gnu
New contributor
add a comment |
I'm writing a Bash script and when inserting lines to a file using GNU sed, the first new line is inserted as a literal n, while the rest is inserted as new lines. The command is this:
sed '5innn' myfile
The output is this:
n
As seen, the first line in the output contains an "n" where it should be none, what am I missing about this behavior? is it possible to make sed insert only new lines with 'n'? Thank you.
bash sed gnu
New contributor
Add a sample of the file that you are working with and the expected output to your question.
– Nasir Riley
31 mins ago
add a comment |
I'm writing a Bash script and when inserting lines to a file using GNU sed, the first new line is inserted as a literal n, while the rest is inserted as new lines. The command is this:
sed '5innn' myfile
The output is this:
n
As seen, the first line in the output contains an "n" where it should be none, what am I missing about this behavior? is it possible to make sed insert only new lines with 'n'? Thank you.
bash sed gnu
New contributor
I'm writing a Bash script and when inserting lines to a file using GNU sed, the first new line is inserted as a literal n, while the rest is inserted as new lines. The command is this:
sed '5innn' myfile
The output is this:
n
As seen, the first line in the output contains an "n" where it should be none, what am I missing about this behavior? is it possible to make sed insert only new lines with 'n'? Thank you.
bash sed gnu
bash sed gnu
New contributor
New contributor
New contributor
asked 49 mins ago
Juli TRJuli TR
81 bronze badge
81 bronze badge
New contributor
New contributor
Add a sample of the file that you are working with and the expected output to your question.
– Nasir Riley
31 mins ago
add a comment |
Add a sample of the file that you are working with and the expected output to your question.
– Nasir Riley
31 mins ago
Add a sample of the file that you are working with and the expected output to your question.
– Nasir Riley
31 mins ago
Add a sample of the file that you are working with and the expected output to your question.
– Nasir Riley
31 mins ago
add a comment |
1 Answer
1
active
oldest
votes
The standard sed
insertion is
5i
text here...
(including the backslash). GNU sed has an extension that accepts the text on the same line as the i
command, but if there's a backslash after the i
it's interpreted as ending the command as usual - though it still doesn't force you to move to a new line, either. You can use
5i\nnn
to do both together. This is not an escaped backslash, but two different kinds of backslash right next to each other. This behaviour doesn't seem to be documented, but is consistent across commands and versions.
You might find it clearer to use another GNU extension:
sed -e '5i' -e 'nnn'
with the command and text split across two -e
arguments to avoid that ambiguity.
You actually don't need the thirdn
. A new line is automatically added at the 5th line so only two of then
are needed. Three of them effectively adds four new lines.
– Nasir Riley
37 mins ago
To be honest, I'm not really clear on how many are actually wanted - this will insert all threen
s and result in four blank lines, which matches one part of the question and not the other. They can be removed (or added) as required to match expectations.
– Michael Homer
33 mins ago
It seems like only three new lines are wanted at the fifth line but I've asked the questionner to add the contents of the file and expected output so it's clearer. Your answer does work but that info may help to understand how it may need to be altered to get the exact output that's wanted.
– Nasir Riley
27 mins ago
add a comment |
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
});
}
});
Juli TR is a new contributor. Be nice, and check out our Code of Conduct.
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%2funix.stackexchange.com%2fquestions%2f531402%2fsed-5i-n-n-n-myfile-inserts-first-n-as-a-literal-n-and-the-other-two-n-n-as%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The standard sed
insertion is
5i
text here...
(including the backslash). GNU sed has an extension that accepts the text on the same line as the i
command, but if there's a backslash after the i
it's interpreted as ending the command as usual - though it still doesn't force you to move to a new line, either. You can use
5i\nnn
to do both together. This is not an escaped backslash, but two different kinds of backslash right next to each other. This behaviour doesn't seem to be documented, but is consistent across commands and versions.
You might find it clearer to use another GNU extension:
sed -e '5i' -e 'nnn'
with the command and text split across two -e
arguments to avoid that ambiguity.
You actually don't need the thirdn
. A new line is automatically added at the 5th line so only two of then
are needed. Three of them effectively adds four new lines.
– Nasir Riley
37 mins ago
To be honest, I'm not really clear on how many are actually wanted - this will insert all threen
s and result in four blank lines, which matches one part of the question and not the other. They can be removed (or added) as required to match expectations.
– Michael Homer
33 mins ago
It seems like only three new lines are wanted at the fifth line but I've asked the questionner to add the contents of the file and expected output so it's clearer. Your answer does work but that info may help to understand how it may need to be altered to get the exact output that's wanted.
– Nasir Riley
27 mins ago
add a comment |
The standard sed
insertion is
5i
text here...
(including the backslash). GNU sed has an extension that accepts the text on the same line as the i
command, but if there's a backslash after the i
it's interpreted as ending the command as usual - though it still doesn't force you to move to a new line, either. You can use
5i\nnn
to do both together. This is not an escaped backslash, but two different kinds of backslash right next to each other. This behaviour doesn't seem to be documented, but is consistent across commands and versions.
You might find it clearer to use another GNU extension:
sed -e '5i' -e 'nnn'
with the command and text split across two -e
arguments to avoid that ambiguity.
You actually don't need the thirdn
. A new line is automatically added at the 5th line so only two of then
are needed. Three of them effectively adds four new lines.
– Nasir Riley
37 mins ago
To be honest, I'm not really clear on how many are actually wanted - this will insert all threen
s and result in four blank lines, which matches one part of the question and not the other. They can be removed (or added) as required to match expectations.
– Michael Homer
33 mins ago
It seems like only three new lines are wanted at the fifth line but I've asked the questionner to add the contents of the file and expected output so it's clearer. Your answer does work but that info may help to understand how it may need to be altered to get the exact output that's wanted.
– Nasir Riley
27 mins ago
add a comment |
The standard sed
insertion is
5i
text here...
(including the backslash). GNU sed has an extension that accepts the text on the same line as the i
command, but if there's a backslash after the i
it's interpreted as ending the command as usual - though it still doesn't force you to move to a new line, either. You can use
5i\nnn
to do both together. This is not an escaped backslash, but two different kinds of backslash right next to each other. This behaviour doesn't seem to be documented, but is consistent across commands and versions.
You might find it clearer to use another GNU extension:
sed -e '5i' -e 'nnn'
with the command and text split across two -e
arguments to avoid that ambiguity.
The standard sed
insertion is
5i
text here...
(including the backslash). GNU sed has an extension that accepts the text on the same line as the i
command, but if there's a backslash after the i
it's interpreted as ending the command as usual - though it still doesn't force you to move to a new line, either. You can use
5i\nnn
to do both together. This is not an escaped backslash, but two different kinds of backslash right next to each other. This behaviour doesn't seem to be documented, but is consistent across commands and versions.
You might find it clearer to use another GNU extension:
sed -e '5i' -e 'nnn'
with the command and text split across two -e
arguments to avoid that ambiguity.
answered 40 mins ago
Michael HomerMichael Homer
54.1k9 gold badges151 silver badges184 bronze badges
54.1k9 gold badges151 silver badges184 bronze badges
You actually don't need the thirdn
. A new line is automatically added at the 5th line so only two of then
are needed. Three of them effectively adds four new lines.
– Nasir Riley
37 mins ago
To be honest, I'm not really clear on how many are actually wanted - this will insert all threen
s and result in four blank lines, which matches one part of the question and not the other. They can be removed (or added) as required to match expectations.
– Michael Homer
33 mins ago
It seems like only three new lines are wanted at the fifth line but I've asked the questionner to add the contents of the file and expected output so it's clearer. Your answer does work but that info may help to understand how it may need to be altered to get the exact output that's wanted.
– Nasir Riley
27 mins ago
add a comment |
You actually don't need the thirdn
. A new line is automatically added at the 5th line so only two of then
are needed. Three of them effectively adds four new lines.
– Nasir Riley
37 mins ago
To be honest, I'm not really clear on how many are actually wanted - this will insert all threen
s and result in four blank lines, which matches one part of the question and not the other. They can be removed (or added) as required to match expectations.
– Michael Homer
33 mins ago
It seems like only three new lines are wanted at the fifth line but I've asked the questionner to add the contents of the file and expected output so it's clearer. Your answer does work but that info may help to understand how it may need to be altered to get the exact output that's wanted.
– Nasir Riley
27 mins ago
You actually don't need the third
n
. A new line is automatically added at the 5th line so only two of the n
are needed. Three of them effectively adds four new lines.– Nasir Riley
37 mins ago
You actually don't need the third
n
. A new line is automatically added at the 5th line so only two of the n
are needed. Three of them effectively adds four new lines.– Nasir Riley
37 mins ago
To be honest, I'm not really clear on how many are actually wanted - this will insert all three
n
s and result in four blank lines, which matches one part of the question and not the other. They can be removed (or added) as required to match expectations.– Michael Homer
33 mins ago
To be honest, I'm not really clear on how many are actually wanted - this will insert all three
n
s and result in four blank lines, which matches one part of the question and not the other. They can be removed (or added) as required to match expectations.– Michael Homer
33 mins ago
It seems like only three new lines are wanted at the fifth line but I've asked the questionner to add the contents of the file and expected output so it's clearer. Your answer does work but that info may help to understand how it may need to be altered to get the exact output that's wanted.
– Nasir Riley
27 mins ago
It seems like only three new lines are wanted at the fifth line but I've asked the questionner to add the contents of the file and expected output so it's clearer. Your answer does work but that info may help to understand how it may need to be altered to get the exact output that's wanted.
– Nasir Riley
27 mins ago
add a comment |
Juli TR is a new contributor. Be nice, and check out our Code of Conduct.
Juli TR is a new contributor. Be nice, and check out our Code of Conduct.
Juli TR is a new contributor. Be nice, and check out our Code of Conduct.
Juli TR is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f531402%2fsed-5i-n-n-n-myfile-inserts-first-n-as-a-literal-n-and-the-other-two-n-n-as%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
Add a sample of the file that you are working with and the expected output to your question.
– Nasir Riley
31 mins ago