How to add Tab Space in between awk / sed command in bash
Clash Royale CLAN TAG#URR8PPP
I have two separate lines being consolidated onto one line. The issue is that at the current moment, it is being separated by a space. I would like to know how I can separate the two lines into one line with a Tab spacing instead.
Here is the code I currently have:
awk '/^loginName:/x=NR+1(NR<=x)print't FinalResults.txt| sed "N;s/n/ /g"
I see the tab command is %t
, but where exactly would this go? Also, can you break down the current coding and explain in detail what everything does and what is the purpose as I am trying to learn how bash works.
Additional information:
The question is related to this answer: https://unix.stackexchange.com/a/502156/330217.
The input file FinalResults.txt
is the same as shown inthe other question.
linux bash awk scripting
add a comment |
I have two separate lines being consolidated onto one line. The issue is that at the current moment, it is being separated by a space. I would like to know how I can separate the two lines into one line with a Tab spacing instead.
Here is the code I currently have:
awk '/^loginName:/x=NR+1(NR<=x)print't FinalResults.txt| sed "N;s/n/ /g"
I see the tab command is %t
, but where exactly would this go? Also, can you break down the current coding and explain in detail what everything does and what is the purpose as I am trying to learn how bash works.
Additional information:
The question is related to this answer: https://unix.stackexchange.com/a/502156/330217.
The input file FinalResults.txt
is the same as shown inthe other question.
linux bash awk scripting
Is this related to unix.stackexchange.com/q/502115/330217 ? Please show your input fileFinalResults.txt
and expected and actual output in the question.
– Bodo
Feb 22 at 15:20
It is, I gave you the best answer to that one. But this one was a shorter script so I was wondering how it worked and just focusing on the Tab command for this. I tried adding the %t everywhere and no luck. I want it to showName
TabMemory
then next line.
– Ibrahim A
Feb 22 at 15:29
add a comment |
I have two separate lines being consolidated onto one line. The issue is that at the current moment, it is being separated by a space. I would like to know how I can separate the two lines into one line with a Tab spacing instead.
Here is the code I currently have:
awk '/^loginName:/x=NR+1(NR<=x)print't FinalResults.txt| sed "N;s/n/ /g"
I see the tab command is %t
, but where exactly would this go? Also, can you break down the current coding and explain in detail what everything does and what is the purpose as I am trying to learn how bash works.
Additional information:
The question is related to this answer: https://unix.stackexchange.com/a/502156/330217.
The input file FinalResults.txt
is the same as shown inthe other question.
linux bash awk scripting
I have two separate lines being consolidated onto one line. The issue is that at the current moment, it is being separated by a space. I would like to know how I can separate the two lines into one line with a Tab spacing instead.
Here is the code I currently have:
awk '/^loginName:/x=NR+1(NR<=x)print't FinalResults.txt| sed "N;s/n/ /g"
I see the tab command is %t
, but where exactly would this go? Also, can you break down the current coding and explain in detail what everything does and what is the purpose as I am trying to learn how bash works.
Additional information:
The question is related to this answer: https://unix.stackexchange.com/a/502156/330217.
The input file FinalResults.txt
is the same as shown inthe other question.
linux bash awk scripting
linux bash awk scripting
edited Feb 22 at 16:27
Bodo
2,251618
2,251618
asked Feb 22 at 14:56
Ibrahim AIbrahim A
379
379
Is this related to unix.stackexchange.com/q/502115/330217 ? Please show your input fileFinalResults.txt
and expected and actual output in the question.
– Bodo
Feb 22 at 15:20
It is, I gave you the best answer to that one. But this one was a shorter script so I was wondering how it worked and just focusing on the Tab command for this. I tried adding the %t everywhere and no luck. I want it to showName
TabMemory
then next line.
– Ibrahim A
Feb 22 at 15:29
add a comment |
Is this related to unix.stackexchange.com/q/502115/330217 ? Please show your input fileFinalResults.txt
and expected and actual output in the question.
– Bodo
Feb 22 at 15:20
It is, I gave you the best answer to that one. But this one was a shorter script so I was wondering how it worked and just focusing on the Tab command for this. I tried adding the %t everywhere and no luck. I want it to showName
TabMemory
then next line.
– Ibrahim A
Feb 22 at 15:29
Is this related to unix.stackexchange.com/q/502115/330217 ? Please show your input file
FinalResults.txt
and expected and actual output in the question.– Bodo
Feb 22 at 15:20
Is this related to unix.stackexchange.com/q/502115/330217 ? Please show your input file
FinalResults.txt
and expected and actual output in the question.– Bodo
Feb 22 at 15:20
It is, I gave you the best answer to that one. But this one was a shorter script so I was wondering how it worked and just focusing on the Tab command for this. I tried adding the %t everywhere and no luck. I want it to show
Name
Tab Memory
then next line.– Ibrahim A
Feb 22 at 15:29
It is, I gave you the best answer to that one. But this one was a shorter script so I was wondering how it worked and just focusing on the Tab command for this. I tried adding the %t everywhere and no luck. I want it to show
Name
Tab Memory
then next line.– Ibrahim A
Feb 22 at 15:29
add a comment |
1 Answer
1
active
oldest
votes
The awk
script prints all lines starting with loginName:
and the next line immediately following it regardless of its contents.
/^loginName:/x=NR+1 # for matching lines store the record (line) number +1 into x
(NR<=x)print # The condition will be true for the line matching the pattern above and the following line.
Read the documentation of sed
and awk
. See https://stackoverflow.com/q/6255796/10622916 for sed
's N
command.
Replace the sed
command with
sed "N;s/n/t/g"
to separate the lines with Tab instead of space.
Or change the awk
script
awk '/^loginName:/x=NR+1;l=$0NR==xprint l "t" $0' FinalResults.txt
and omit the sed
command.
If you want it even shorter
awk 'lprint l"t"$0;l=0/^loginName:/l=$0' FinalResults.txt
but a shorter script may be more difficult to understand.
(Here the condition for printing is the value of l
being non-empty and not 0
, and l
stores the loginName:
line.)
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
);
);
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%2f502329%2fhow-to-add-tab-space-in-between-awk-sed-command-in-bash%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 awk
script prints all lines starting with loginName:
and the next line immediately following it regardless of its contents.
/^loginName:/x=NR+1 # for matching lines store the record (line) number +1 into x
(NR<=x)print # The condition will be true for the line matching the pattern above and the following line.
Read the documentation of sed
and awk
. See https://stackoverflow.com/q/6255796/10622916 for sed
's N
command.
Replace the sed
command with
sed "N;s/n/t/g"
to separate the lines with Tab instead of space.
Or change the awk
script
awk '/^loginName:/x=NR+1;l=$0NR==xprint l "t" $0' FinalResults.txt
and omit the sed
command.
If you want it even shorter
awk 'lprint l"t"$0;l=0/^loginName:/l=$0' FinalResults.txt
but a shorter script may be more difficult to understand.
(Here the condition for printing is the value of l
being non-empty and not 0
, and l
stores the loginName:
line.)
add a comment |
The awk
script prints all lines starting with loginName:
and the next line immediately following it regardless of its contents.
/^loginName:/x=NR+1 # for matching lines store the record (line) number +1 into x
(NR<=x)print # The condition will be true for the line matching the pattern above and the following line.
Read the documentation of sed
and awk
. See https://stackoverflow.com/q/6255796/10622916 for sed
's N
command.
Replace the sed
command with
sed "N;s/n/t/g"
to separate the lines with Tab instead of space.
Or change the awk
script
awk '/^loginName:/x=NR+1;l=$0NR==xprint l "t" $0' FinalResults.txt
and omit the sed
command.
If you want it even shorter
awk 'lprint l"t"$0;l=0/^loginName:/l=$0' FinalResults.txt
but a shorter script may be more difficult to understand.
(Here the condition for printing is the value of l
being non-empty and not 0
, and l
stores the loginName:
line.)
add a comment |
The awk
script prints all lines starting with loginName:
and the next line immediately following it regardless of its contents.
/^loginName:/x=NR+1 # for matching lines store the record (line) number +1 into x
(NR<=x)print # The condition will be true for the line matching the pattern above and the following line.
Read the documentation of sed
and awk
. See https://stackoverflow.com/q/6255796/10622916 for sed
's N
command.
Replace the sed
command with
sed "N;s/n/t/g"
to separate the lines with Tab instead of space.
Or change the awk
script
awk '/^loginName:/x=NR+1;l=$0NR==xprint l "t" $0' FinalResults.txt
and omit the sed
command.
If you want it even shorter
awk 'lprint l"t"$0;l=0/^loginName:/l=$0' FinalResults.txt
but a shorter script may be more difficult to understand.
(Here the condition for printing is the value of l
being non-empty and not 0
, and l
stores the loginName:
line.)
The awk
script prints all lines starting with loginName:
and the next line immediately following it regardless of its contents.
/^loginName:/x=NR+1 # for matching lines store the record (line) number +1 into x
(NR<=x)print # The condition will be true for the line matching the pattern above and the following line.
Read the documentation of sed
and awk
. See https://stackoverflow.com/q/6255796/10622916 for sed
's N
command.
Replace the sed
command with
sed "N;s/n/t/g"
to separate the lines with Tab instead of space.
Or change the awk
script
awk '/^loginName:/x=NR+1;l=$0NR==xprint l "t" $0' FinalResults.txt
and omit the sed
command.
If you want it even shorter
awk 'lprint l"t"$0;l=0/^loginName:/l=$0' FinalResults.txt
but a shorter script may be more difficult to understand.
(Here the condition for printing is the value of l
being non-empty and not 0
, and l
stores the loginName:
line.)
edited Feb 22 at 15:46
answered Feb 22 at 15:31
BodoBodo
2,251618
2,251618
add a comment |
add a comment |
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%2f502329%2fhow-to-add-tab-space-in-between-awk-sed-command-in-bash%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
Is this related to unix.stackexchange.com/q/502115/330217 ? Please show your input file
FinalResults.txt
and expected and actual output in the question.– Bodo
Feb 22 at 15:20
It is, I gave you the best answer to that one. But this one was a shorter script so I was wondering how it worked and just focusing on the Tab command for this. I tried adding the %t everywhere and no luck. I want it to show
Name
TabMemory
then next line.– Ibrahim A
Feb 22 at 15:29