Add line breaks to Grep Commands
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
How can I add a few line breaks? I want it to show OpenFin
category, have a line break, Chrome
category, another line break, then memoryInfo
.
Here is what I have so far:
cat LoginExInternal.txt | grep OpenFin >> LoginExcInternal.txt | echo $'r'
&& cat LoginExInternal.txt | grep Chrome >> LoginExcInternal.txt | echo $'r'
&& cat MemoryUnderThreshold.txt | grep memoryInfo:jsHeapSizeLimit:1 >> LoginExcInternal.txt | echo $'r'
I can't seem to get it into new lines though, the echo $'r'
doesn't seem to work. Please tell me how I can modify to make this work.
linux bash text-processing cygwin word-processing
add a comment |
How can I add a few line breaks? I want it to show OpenFin
category, have a line break, Chrome
category, another line break, then memoryInfo
.
Here is what I have so far:
cat LoginExInternal.txt | grep OpenFin >> LoginExcInternal.txt | echo $'r'
&& cat LoginExInternal.txt | grep Chrome >> LoginExcInternal.txt | echo $'r'
&& cat MemoryUnderThreshold.txt | grep memoryInfo:jsHeapSizeLimit:1 >> LoginExcInternal.txt | echo $'r'
I can't seem to get it into new lines though, the echo $'r'
doesn't seem to work. Please tell me how I can modify to make this work.
linux bash text-processing cygwin word-processing
1
It would help to see (a reasonable part of) the contents of your filesLoginExInternal.txt
andMemoryUnderThreshold.txt
and how the result should look like. Do you user
(CR
) to get DOS/Windows line endings (r
+n
orCR
+LF
)?
– Bodo
Mar 13 at 13:10
add a comment |
How can I add a few line breaks? I want it to show OpenFin
category, have a line break, Chrome
category, another line break, then memoryInfo
.
Here is what I have so far:
cat LoginExInternal.txt | grep OpenFin >> LoginExcInternal.txt | echo $'r'
&& cat LoginExInternal.txt | grep Chrome >> LoginExcInternal.txt | echo $'r'
&& cat MemoryUnderThreshold.txt | grep memoryInfo:jsHeapSizeLimit:1 >> LoginExcInternal.txt | echo $'r'
I can't seem to get it into new lines though, the echo $'r'
doesn't seem to work. Please tell me how I can modify to make this work.
linux bash text-processing cygwin word-processing
How can I add a few line breaks? I want it to show OpenFin
category, have a line break, Chrome
category, another line break, then memoryInfo
.
Here is what I have so far:
cat LoginExInternal.txt | grep OpenFin >> LoginExcInternal.txt | echo $'r'
&& cat LoginExInternal.txt | grep Chrome >> LoginExcInternal.txt | echo $'r'
&& cat MemoryUnderThreshold.txt | grep memoryInfo:jsHeapSizeLimit:1 >> LoginExcInternal.txt | echo $'r'
I can't seem to get it into new lines though, the echo $'r'
doesn't seem to work. Please tell me how I can modify to make this work.
linux bash text-processing cygwin word-processing
linux bash text-processing cygwin word-processing
asked Mar 13 at 12:49
Ibrahim AIbrahim A
419
419
1
It would help to see (a reasonable part of) the contents of your filesLoginExInternal.txt
andMemoryUnderThreshold.txt
and how the result should look like. Do you user
(CR
) to get DOS/Windows line endings (r
+n
orCR
+LF
)?
– Bodo
Mar 13 at 13:10
add a comment |
1
It would help to see (a reasonable part of) the contents of your filesLoginExInternal.txt
andMemoryUnderThreshold.txt
and how the result should look like. Do you user
(CR
) to get DOS/Windows line endings (r
+n
orCR
+LF
)?
– Bodo
Mar 13 at 13:10
1
1
It would help to see (a reasonable part of) the contents of your files
LoginExInternal.txt
and MemoryUnderThreshold.txt
and how the result should look like. Do you use r
(CR
) to get DOS/Windows line endings (r
+n
or CR
+LF
)?– Bodo
Mar 13 at 13:10
It would help to see (a reasonable part of) the contents of your files
LoginExInternal.txt
and MemoryUnderThreshold.txt
and how the result should look like. Do you use r
(CR
) to get DOS/Windows line endings (r
+n
or CR
+LF
)?– Bodo
Mar 13 at 13:10
add a comment |
2 Answers
2
active
oldest
votes
You don't need to use cat
with grep
, and you can group the commands to only put the redirection there once:
grep OpenFin < LoginExInternal.txt && echo
grep Chrome < LoginExInternal.txt && echo
grep memoryInfo:jsHeapSizeLimit:1 < MemoryUnderThreshold.txt && echo
>> LoginExcInternal.txt
Note also that if you join all the commands with &&
, then a failing grep will stop the following echo
, but also the rest of the grep
s from running. That may or may not be what you want. Using just grep && echo
as above would have all the grep
s run in any case, but only print the extra newlines when the grep
matches something.
Also, I'm not exactly sure how linebreaks are handled in cygwin, that is, if explicitly printing out the carriage return $'r'
is required.
This did not work for me. This is a part of a bigger script, when I added it, it said the grep command was not found. I think I will use what I have as it works, thanks for trying to help!
– Ibrahim A
Mar 13 at 13:50
@IbrahimA, grouping with braces shouldn't affect what commands are found or not, so if you had grep working in the original, I can't see why it wouldn't work here.
– ilkkachu
Mar 13 at 13:55
add a comment |
This seems to work. I am not sure if there is a simpler way to do this:
grep OpenFin LoginExInternal.txt >> LoginExcInternal.txt &&
echo $'r' >> LoginExcInternal.txt &&
grep Chrome LoginExInternal.txt >> LoginExcInternal.txt &&
echo $'r' >> LoginExcInternal.txt &&
grep MemoryUnderThreshold.txt memoryInfo:jsHeapSizeLimit:1 >> LoginExcInternal.txt
1
You don't need thecat
commands. Instead ofcat filename | grep pattern
simply usegrep pattern filename
.
– Bodo
Mar 13 at 13:12
Great Point! I just changed it and it works perfectly.
– Ibrahim A
Mar 13 at 13:16
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%2f506088%2fadd-line-breaks-to-grep-commands%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You don't need to use cat
with grep
, and you can group the commands to only put the redirection there once:
grep OpenFin < LoginExInternal.txt && echo
grep Chrome < LoginExInternal.txt && echo
grep memoryInfo:jsHeapSizeLimit:1 < MemoryUnderThreshold.txt && echo
>> LoginExcInternal.txt
Note also that if you join all the commands with &&
, then a failing grep will stop the following echo
, but also the rest of the grep
s from running. That may or may not be what you want. Using just grep && echo
as above would have all the grep
s run in any case, but only print the extra newlines when the grep
matches something.
Also, I'm not exactly sure how linebreaks are handled in cygwin, that is, if explicitly printing out the carriage return $'r'
is required.
This did not work for me. This is a part of a bigger script, when I added it, it said the grep command was not found. I think I will use what I have as it works, thanks for trying to help!
– Ibrahim A
Mar 13 at 13:50
@IbrahimA, grouping with braces shouldn't affect what commands are found or not, so if you had grep working in the original, I can't see why it wouldn't work here.
– ilkkachu
Mar 13 at 13:55
add a comment |
You don't need to use cat
with grep
, and you can group the commands to only put the redirection there once:
grep OpenFin < LoginExInternal.txt && echo
grep Chrome < LoginExInternal.txt && echo
grep memoryInfo:jsHeapSizeLimit:1 < MemoryUnderThreshold.txt && echo
>> LoginExcInternal.txt
Note also that if you join all the commands with &&
, then a failing grep will stop the following echo
, but also the rest of the grep
s from running. That may or may not be what you want. Using just grep && echo
as above would have all the grep
s run in any case, but only print the extra newlines when the grep
matches something.
Also, I'm not exactly sure how linebreaks are handled in cygwin, that is, if explicitly printing out the carriage return $'r'
is required.
This did not work for me. This is a part of a bigger script, when I added it, it said the grep command was not found. I think I will use what I have as it works, thanks for trying to help!
– Ibrahim A
Mar 13 at 13:50
@IbrahimA, grouping with braces shouldn't affect what commands are found or not, so if you had grep working in the original, I can't see why it wouldn't work here.
– ilkkachu
Mar 13 at 13:55
add a comment |
You don't need to use cat
with grep
, and you can group the commands to only put the redirection there once:
grep OpenFin < LoginExInternal.txt && echo
grep Chrome < LoginExInternal.txt && echo
grep memoryInfo:jsHeapSizeLimit:1 < MemoryUnderThreshold.txt && echo
>> LoginExcInternal.txt
Note also that if you join all the commands with &&
, then a failing grep will stop the following echo
, but also the rest of the grep
s from running. That may or may not be what you want. Using just grep && echo
as above would have all the grep
s run in any case, but only print the extra newlines when the grep
matches something.
Also, I'm not exactly sure how linebreaks are handled in cygwin, that is, if explicitly printing out the carriage return $'r'
is required.
You don't need to use cat
with grep
, and you can group the commands to only put the redirection there once:
grep OpenFin < LoginExInternal.txt && echo
grep Chrome < LoginExInternal.txt && echo
grep memoryInfo:jsHeapSizeLimit:1 < MemoryUnderThreshold.txt && echo
>> LoginExcInternal.txt
Note also that if you join all the commands with &&
, then a failing grep will stop the following echo
, but also the rest of the grep
s from running. That may or may not be what you want. Using just grep && echo
as above would have all the grep
s run in any case, but only print the extra newlines when the grep
matches something.
Also, I'm not exactly sure how linebreaks are handled in cygwin, that is, if explicitly printing out the carriage return $'r'
is required.
answered Mar 13 at 13:13
ilkkachuilkkachu
63.4k10104181
63.4k10104181
This did not work for me. This is a part of a bigger script, when I added it, it said the grep command was not found. I think I will use what I have as it works, thanks for trying to help!
– Ibrahim A
Mar 13 at 13:50
@IbrahimA, grouping with braces shouldn't affect what commands are found or not, so if you had grep working in the original, I can't see why it wouldn't work here.
– ilkkachu
Mar 13 at 13:55
add a comment |
This did not work for me. This is a part of a bigger script, when I added it, it said the grep command was not found. I think I will use what I have as it works, thanks for trying to help!
– Ibrahim A
Mar 13 at 13:50
@IbrahimA, grouping with braces shouldn't affect what commands are found or not, so if you had grep working in the original, I can't see why it wouldn't work here.
– ilkkachu
Mar 13 at 13:55
This did not work for me. This is a part of a bigger script, when I added it, it said the grep command was not found. I think I will use what I have as it works, thanks for trying to help!
– Ibrahim A
Mar 13 at 13:50
This did not work for me. This is a part of a bigger script, when I added it, it said the grep command was not found. I think I will use what I have as it works, thanks for trying to help!
– Ibrahim A
Mar 13 at 13:50
@IbrahimA, grouping with braces shouldn't affect what commands are found or not, so if you had grep working in the original, I can't see why it wouldn't work here.
– ilkkachu
Mar 13 at 13:55
@IbrahimA, grouping with braces shouldn't affect what commands are found or not, so if you had grep working in the original, I can't see why it wouldn't work here.
– ilkkachu
Mar 13 at 13:55
add a comment |
This seems to work. I am not sure if there is a simpler way to do this:
grep OpenFin LoginExInternal.txt >> LoginExcInternal.txt &&
echo $'r' >> LoginExcInternal.txt &&
grep Chrome LoginExInternal.txt >> LoginExcInternal.txt &&
echo $'r' >> LoginExcInternal.txt &&
grep MemoryUnderThreshold.txt memoryInfo:jsHeapSizeLimit:1 >> LoginExcInternal.txt
1
You don't need thecat
commands. Instead ofcat filename | grep pattern
simply usegrep pattern filename
.
– Bodo
Mar 13 at 13:12
Great Point! I just changed it and it works perfectly.
– Ibrahim A
Mar 13 at 13:16
add a comment |
This seems to work. I am not sure if there is a simpler way to do this:
grep OpenFin LoginExInternal.txt >> LoginExcInternal.txt &&
echo $'r' >> LoginExcInternal.txt &&
grep Chrome LoginExInternal.txt >> LoginExcInternal.txt &&
echo $'r' >> LoginExcInternal.txt &&
grep MemoryUnderThreshold.txt memoryInfo:jsHeapSizeLimit:1 >> LoginExcInternal.txt
1
You don't need thecat
commands. Instead ofcat filename | grep pattern
simply usegrep pattern filename
.
– Bodo
Mar 13 at 13:12
Great Point! I just changed it and it works perfectly.
– Ibrahim A
Mar 13 at 13:16
add a comment |
This seems to work. I am not sure if there is a simpler way to do this:
grep OpenFin LoginExInternal.txt >> LoginExcInternal.txt &&
echo $'r' >> LoginExcInternal.txt &&
grep Chrome LoginExInternal.txt >> LoginExcInternal.txt &&
echo $'r' >> LoginExcInternal.txt &&
grep MemoryUnderThreshold.txt memoryInfo:jsHeapSizeLimit:1 >> LoginExcInternal.txt
This seems to work. I am not sure if there is a simpler way to do this:
grep OpenFin LoginExInternal.txt >> LoginExcInternal.txt &&
echo $'r' >> LoginExcInternal.txt &&
grep Chrome LoginExInternal.txt >> LoginExcInternal.txt &&
echo $'r' >> LoginExcInternal.txt &&
grep MemoryUnderThreshold.txt memoryInfo:jsHeapSizeLimit:1 >> LoginExcInternal.txt
edited Mar 13 at 13:18
answered Mar 13 at 12:57
Ibrahim AIbrahim A
419
419
1
You don't need thecat
commands. Instead ofcat filename | grep pattern
simply usegrep pattern filename
.
– Bodo
Mar 13 at 13:12
Great Point! I just changed it and it works perfectly.
– Ibrahim A
Mar 13 at 13:16
add a comment |
1
You don't need thecat
commands. Instead ofcat filename | grep pattern
simply usegrep pattern filename
.
– Bodo
Mar 13 at 13:12
Great Point! I just changed it and it works perfectly.
– Ibrahim A
Mar 13 at 13:16
1
1
You don't need the
cat
commands. Instead of cat filename | grep pattern
simply use grep pattern filename
.– Bodo
Mar 13 at 13:12
You don't need the
cat
commands. Instead of cat filename | grep pattern
simply use grep pattern filename
.– Bodo
Mar 13 at 13:12
Great Point! I just changed it and it works perfectly.
– Ibrahim A
Mar 13 at 13:16
Great Point! I just changed it and it works perfectly.
– Ibrahim A
Mar 13 at 13:16
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%2f506088%2fadd-line-breaks-to-grep-commands%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
1
It would help to see (a reasonable part of) the contents of your files
LoginExInternal.txt
andMemoryUnderThreshold.txt
and how the result should look like. Do you user
(CR
) to get DOS/Windows line endings (r
+n
orCR
+LF
)?– Bodo
Mar 13 at 13:10