Add line breaks to Grep Commands

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








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.










share|improve this question

















  • 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

















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.










share|improve this question

















  • 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













0












0








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.










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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












  • 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







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










2 Answers
2






active

oldest

votes


















2














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 greps from running. That may or may not be what you want. Using just grep && echo as above would have all the greps 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.






share|improve this answer























  • 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


















0














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





share|improve this answer




















  • 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












  • Great Point! I just changed it and it works perfectly.

    – Ibrahim A
    Mar 13 at 13:16











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
);



);













draft saved

draft discarded


















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









2














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 greps from running. That may or may not be what you want. Using just grep && echo as above would have all the greps 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.






share|improve this answer























  • 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















2














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 greps from running. That may or may not be what you want. Using just grep && echo as above would have all the greps 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.






share|improve this answer























  • 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













2












2








2







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 greps from running. That may or may not be what you want. Using just grep && echo as above would have all the greps 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.






share|improve this answer













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 greps from running. That may or may not be what you want. Using just grep && echo as above would have all the greps 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.







share|improve this answer












share|improve this answer



share|improve this answer










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

















  • 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













0














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





share|improve this answer




















  • 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












  • Great Point! I just changed it and it works perfectly.

    – Ibrahim A
    Mar 13 at 13:16















0














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





share|improve this answer




















  • 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












  • Great Point! I just changed it and it works perfectly.

    – Ibrahim A
    Mar 13 at 13:16













0












0








0







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





share|improve this answer















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






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 13 at 13:18

























answered Mar 13 at 12:57









Ibrahim AIbrahim A

419




419







  • 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












  • Great Point! I just changed it and it works perfectly.

    – Ibrahim A
    Mar 13 at 13:16












  • 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












  • 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

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?