Space with grep? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Use grep --exclude/--include syntax to not grep through certain filesIs PowerShell ready to replace my Cygwin shell on Windows?Colorized grep — viewing the entire file with highlighted matchesCapturing Groups From a Grep RegExConvert numbers to enumeration of strings in bashHow to 'grep' a continuous stream?Find Day in The shell scriptCrontab scheduling confusionI want grep to grep one word which is having spaces itget matchin words from text (exactly netbackup 'bpllist' command output )

Is there a kind of relay only consumes power when switching?

Did MS DOS itself ever use blinking text?

old style "caution" boxes

Is there such thing as an Availability Group failover trigger?

Withdrew £2800, but only £2000 shows as withdrawn on online banking; what are my obligations?

Significance of Cersei's obsession with elephants?

How can I use the Python library networkx from Mathematica?

2001: A Space Odyssey's use of the song "Daisy Bell" (Bicycle Built for Two); life imitates art or vice-versa?

Wu formula for manifolds with boundary

Trademark violation for app?

Compare a given version number in the form major.minor.build.patch and see if one is less than the other

Why didn't Eitri join the fight?

What's the meaning of "fortified infraction restraint"?

When the Haste spell ends on a creature, do attackers have advantage against that creature?

Is safe to use va_start macro with this as parameter?

Chinese Seal on silk painting - what does it mean?

How to react to hostile behavior from a senior developer?

Is it fair for a professor to grade us on the possession of past papers?

Why are both D and D# fitting into my E minor key?

Why wasn't DOSKEY integrated with COMMAND.COM?

First console to have temporary backward compatibility

Crossing US/Canada Border for less than 24 hours

Amount of permutations on an NxNxN Rubik's Cube

Why aren't air breathing engines used as small first stages



Space with grep?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Use grep --exclude/--include syntax to not grep through certain filesIs PowerShell ready to replace my Cygwin shell on Windows?Colorized grep — viewing the entire file with highlighted matchesCapturing Groups From a Grep RegExConvert numbers to enumeration of strings in bashHow to 'grep' a continuous stream?Find Day in The shell scriptCrontab scheduling confusionI want grep to grep one word which is having spaces itget matchin words from text (exactly netbackup 'bpllist' command output )



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I have a csv file like this :



Monday
Tuesday
Wednesday
Thursday
Friday


I would like to analyze an other csv file with the csv file with the days of the week. My script will take Monday, analyze the file and extract all the lines that contain the word Monday, then switch to Tuesday etc....



I use this command to do this :



grep -wf daysfile.csv myothercsv.csv > file.csv


This command works pretty well, but the result is :



Monday XXXX XXX XXX
Monday XXXX XXX XXX
Monday XXXX XXX XXX
Monday XXXX XXX XXX
Tuesday XXXX XXXX XXXX
Tuesday XXXX XXXX XXXX
Tuesday XXXX XXXX XXXX
Tuesday XXXX XXXX XXXX
Tuesday XXXX XXXX XXXX
Wednesday XXXX XXXX XXXX
Wednesday XXXX XXXX XXXX
Wednesday XXXX XXXX XXXX
Wednesday XXXX XXXX XXXX


But I would like to have spaces like this :



Monday XXXX XXX XXX
Monday XXXX XXX XXX
Monday XXXX XXX XXX
Monday XXXX XXX XXX

Tuesday XXXX XXXX XXXX
Tuesday XXXX XXXX XXXX
Tuesday XXXX XXXX XXXX
Tuesday XXXX XXXX XXXX


Can you help me ?










share|improve this question




























    1















    I have a csv file like this :



    Monday
    Tuesday
    Wednesday
    Thursday
    Friday


    I would like to analyze an other csv file with the csv file with the days of the week. My script will take Monday, analyze the file and extract all the lines that contain the word Monday, then switch to Tuesday etc....



    I use this command to do this :



    grep -wf daysfile.csv myothercsv.csv > file.csv


    This command works pretty well, but the result is :



    Monday XXXX XXX XXX
    Monday XXXX XXX XXX
    Monday XXXX XXX XXX
    Monday XXXX XXX XXX
    Tuesday XXXX XXXX XXXX
    Tuesday XXXX XXXX XXXX
    Tuesday XXXX XXXX XXXX
    Tuesday XXXX XXXX XXXX
    Tuesday XXXX XXXX XXXX
    Wednesday XXXX XXXX XXXX
    Wednesday XXXX XXXX XXXX
    Wednesday XXXX XXXX XXXX
    Wednesday XXXX XXXX XXXX


    But I would like to have spaces like this :



    Monday XXXX XXX XXX
    Monday XXXX XXX XXX
    Monday XXXX XXX XXX
    Monday XXXX XXX XXX

    Tuesday XXXX XXXX XXXX
    Tuesday XXXX XXXX XXXX
    Tuesday XXXX XXXX XXXX
    Tuesday XXXX XXXX XXXX


    Can you help me ?










    share|improve this question
























      1












      1








      1








      I have a csv file like this :



      Monday
      Tuesday
      Wednesday
      Thursday
      Friday


      I would like to analyze an other csv file with the csv file with the days of the week. My script will take Monday, analyze the file and extract all the lines that contain the word Monday, then switch to Tuesday etc....



      I use this command to do this :



      grep -wf daysfile.csv myothercsv.csv > file.csv


      This command works pretty well, but the result is :



      Monday XXXX XXX XXX
      Monday XXXX XXX XXX
      Monday XXXX XXX XXX
      Monday XXXX XXX XXX
      Tuesday XXXX XXXX XXXX
      Tuesday XXXX XXXX XXXX
      Tuesday XXXX XXXX XXXX
      Tuesday XXXX XXXX XXXX
      Tuesday XXXX XXXX XXXX
      Wednesday XXXX XXXX XXXX
      Wednesday XXXX XXXX XXXX
      Wednesday XXXX XXXX XXXX
      Wednesday XXXX XXXX XXXX


      But I would like to have spaces like this :



      Monday XXXX XXX XXX
      Monday XXXX XXX XXX
      Monday XXXX XXX XXX
      Monday XXXX XXX XXX

      Tuesday XXXX XXXX XXXX
      Tuesday XXXX XXXX XXXX
      Tuesday XXXX XXXX XXXX
      Tuesday XXXX XXXX XXXX


      Can you help me ?










      share|improve this question














      I have a csv file like this :



      Monday
      Tuesday
      Wednesday
      Thursday
      Friday


      I would like to analyze an other csv file with the csv file with the days of the week. My script will take Monday, analyze the file and extract all the lines that contain the word Monday, then switch to Tuesday etc....



      I use this command to do this :



      grep -wf daysfile.csv myothercsv.csv > file.csv


      This command works pretty well, but the result is :



      Monday XXXX XXX XXX
      Monday XXXX XXX XXX
      Monday XXXX XXX XXX
      Monday XXXX XXX XXX
      Tuesday XXXX XXXX XXXX
      Tuesday XXXX XXXX XXXX
      Tuesday XXXX XXXX XXXX
      Tuesday XXXX XXXX XXXX
      Tuesday XXXX XXXX XXXX
      Wednesday XXXX XXXX XXXX
      Wednesday XXXX XXXX XXXX
      Wednesday XXXX XXXX XXXX
      Wednesday XXXX XXXX XXXX


      But I would like to have spaces like this :



      Monday XXXX XXX XXX
      Monday XXXX XXX XXX
      Monday XXXX XXX XXX
      Monday XXXX XXX XXX

      Tuesday XXXX XXXX XXXX
      Tuesday XXXX XXXX XXXX
      Tuesday XXXX XXXX XXXX
      Tuesday XXXX XXXX XXXX


      Can you help me ?







      bash shell awk






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 18:58









      EzzmazzEzzmazz

      213




      213






















          4 Answers
          4






          active

          oldest

          votes


















          0














          Use awk



          grep -wf daysfile.csv myothercsv.csv |awk -F: 'if(f!=$1)print ""; f=$1; print $0;'

          Monday XXXX XXX XXX
          Monday XXXX XXX XXX
          Monday XXXX XXX XXX
          Monday XXXX XXX XXX

          Tuesday XXXX XXXX XXXX
          Tuesday XXXX XXXX XXXX
          Tuesday XXXX XXXX XXXX
          Tuesday XXXX XXXX XXXX
          Tuesday XXXX XXXX XXXX

          Wednesday XXXX XXXX XXXX
          Wednesday XXXX XXXX XXXX
          Wednesday XXXX XXXX XXXX
          Wednesday XXXX XXXX XXXX





          share|improve this answer


















          • 1





            IMHO, I am not sure if OP has mentioned that : is field separator, may be you are trying to do which I did on this stackoverflow.com/a/55069502/5866580

            – RavinderSingh13
            Mar 8 at 19:13











          • Your command worke very well ! But it only adds one space between each group of days. Can you tell me how to put 2 spaces between them ?

            – Ezzmazz
            Mar 20 at 10:43











          • Change print "" with print "n"

            – Sonny
            Mar 20 at 11:13


















          1














          Just pipe the output of grep to



          perl -ape 'print "n" if $previous and $previous ne $F[0]; $previous = $F[0]'



          • -p reads the input line by line and prints each line after processing


          • -a splits each input line into the @F array





          share|improve this answer






























            0














            In awk could you please try following.



            your_grep_command | awk 'prev!=$1 && prevprint "" prev=$1;print' 




            Since OP has NOT provided samples so couldn't test it, could you please try to run directly this command? In spite of passing grep output to another command once and let us know then.



            awk 'FNR==NRa[$0];next prev!=$1print "" ($0 in a);prev=$1' daysfile.csv <(sort -k1 myothercsv.csv)





            share|improve this answer

























            • @Ezzmazz, could you please check this solution once and let me now if this helps you?

              – RavinderSingh13
              Mar 9 at 12:18


















            0














            I'm not sure how grep -wf daysfile.csv myothercsv.csv is working for you as you described. The data in myothercsv.csv must already be sorted by days of the week, since the grep command would simply print any line that has any matching word in the daysfile.csv as they are ordered.



            If you want to search for each word in the daysfile.csv sequentially, then you probably want following:



            cat daysfile.csv | while read line; do grep "$line" myothercsv.csv; done


            Then you can apply the other answers here that refer to adding blank lines (when a different first word is detected) to the output.



            Also, a different way to do this is to insert a blank line into myothercsv file, and insert ^$ lines to your daysfile. Here's an example, notice the first line in myothercsv file is a blank.



            $ cat daysfile.csv
            mon
            ^$
            tue
            ^$
            wed
            ^$

            $ cat myothercsv.csv

            mon,1
            tue,2
            wed,3
            mon,4
            tue,5
            wed,6

            $ cat daysfile.csv | while read line; do grep "$line" myothercsv.csv; done
            mon,1
            mon,4

            tue,2
            tue,5

            wed,3
            wed,6





            share|improve this answer

























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              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
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069384%2fspace-with-grep%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









              0














              Use awk



              grep -wf daysfile.csv myothercsv.csv |awk -F: 'if(f!=$1)print ""; f=$1; print $0;'

              Monday XXXX XXX XXX
              Monday XXXX XXX XXX
              Monday XXXX XXX XXX
              Monday XXXX XXX XXX

              Tuesday XXXX XXXX XXXX
              Tuesday XXXX XXXX XXXX
              Tuesday XXXX XXXX XXXX
              Tuesday XXXX XXXX XXXX
              Tuesday XXXX XXXX XXXX

              Wednesday XXXX XXXX XXXX
              Wednesday XXXX XXXX XXXX
              Wednesday XXXX XXXX XXXX
              Wednesday XXXX XXXX XXXX





              share|improve this answer


















              • 1





                IMHO, I am not sure if OP has mentioned that : is field separator, may be you are trying to do which I did on this stackoverflow.com/a/55069502/5866580

                – RavinderSingh13
                Mar 8 at 19:13











              • Your command worke very well ! But it only adds one space between each group of days. Can you tell me how to put 2 spaces between them ?

                – Ezzmazz
                Mar 20 at 10:43











              • Change print "" with print "n"

                – Sonny
                Mar 20 at 11:13















              0














              Use awk



              grep -wf daysfile.csv myothercsv.csv |awk -F: 'if(f!=$1)print ""; f=$1; print $0;'

              Monday XXXX XXX XXX
              Monday XXXX XXX XXX
              Monday XXXX XXX XXX
              Monday XXXX XXX XXX

              Tuesday XXXX XXXX XXXX
              Tuesday XXXX XXXX XXXX
              Tuesday XXXX XXXX XXXX
              Tuesday XXXX XXXX XXXX
              Tuesday XXXX XXXX XXXX

              Wednesday XXXX XXXX XXXX
              Wednesday XXXX XXXX XXXX
              Wednesday XXXX XXXX XXXX
              Wednesday XXXX XXXX XXXX





              share|improve this answer


















              • 1





                IMHO, I am not sure if OP has mentioned that : is field separator, may be you are trying to do which I did on this stackoverflow.com/a/55069502/5866580

                – RavinderSingh13
                Mar 8 at 19:13











              • Your command worke very well ! But it only adds one space between each group of days. Can you tell me how to put 2 spaces between them ?

                – Ezzmazz
                Mar 20 at 10:43











              • Change print "" with print "n"

                – Sonny
                Mar 20 at 11:13













              0












              0








              0







              Use awk



              grep -wf daysfile.csv myothercsv.csv |awk -F: 'if(f!=$1)print ""; f=$1; print $0;'

              Monday XXXX XXX XXX
              Monday XXXX XXX XXX
              Monday XXXX XXX XXX
              Monday XXXX XXX XXX

              Tuesday XXXX XXXX XXXX
              Tuesday XXXX XXXX XXXX
              Tuesday XXXX XXXX XXXX
              Tuesday XXXX XXXX XXXX
              Tuesday XXXX XXXX XXXX

              Wednesday XXXX XXXX XXXX
              Wednesday XXXX XXXX XXXX
              Wednesday XXXX XXXX XXXX
              Wednesday XXXX XXXX XXXX





              share|improve this answer













              Use awk



              grep -wf daysfile.csv myothercsv.csv |awk -F: 'if(f!=$1)print ""; f=$1; print $0;'

              Monday XXXX XXX XXX
              Monday XXXX XXX XXX
              Monday XXXX XXX XXX
              Monday XXXX XXX XXX

              Tuesday XXXX XXXX XXXX
              Tuesday XXXX XXXX XXXX
              Tuesday XXXX XXXX XXXX
              Tuesday XXXX XXXX XXXX
              Tuesday XXXX XXXX XXXX

              Wednesday XXXX XXXX XXXX
              Wednesday XXXX XXXX XXXX
              Wednesday XXXX XXXX XXXX
              Wednesday XXXX XXXX XXXX






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 8 at 19:09









              SonnySonny

              2,1561516




              2,1561516







              • 1





                IMHO, I am not sure if OP has mentioned that : is field separator, may be you are trying to do which I did on this stackoverflow.com/a/55069502/5866580

                – RavinderSingh13
                Mar 8 at 19:13











              • Your command worke very well ! But it only adds one space between each group of days. Can you tell me how to put 2 spaces between them ?

                – Ezzmazz
                Mar 20 at 10:43











              • Change print "" with print "n"

                – Sonny
                Mar 20 at 11:13












              • 1





                IMHO, I am not sure if OP has mentioned that : is field separator, may be you are trying to do which I did on this stackoverflow.com/a/55069502/5866580

                – RavinderSingh13
                Mar 8 at 19:13











              • Your command worke very well ! But it only adds one space between each group of days. Can you tell me how to put 2 spaces between them ?

                – Ezzmazz
                Mar 20 at 10:43











              • Change print "" with print "n"

                – Sonny
                Mar 20 at 11:13







              1




              1





              IMHO, I am not sure if OP has mentioned that : is field separator, may be you are trying to do which I did on this stackoverflow.com/a/55069502/5866580

              – RavinderSingh13
              Mar 8 at 19:13





              IMHO, I am not sure if OP has mentioned that : is field separator, may be you are trying to do which I did on this stackoverflow.com/a/55069502/5866580

              – RavinderSingh13
              Mar 8 at 19:13













              Your command worke very well ! But it only adds one space between each group of days. Can you tell me how to put 2 spaces between them ?

              – Ezzmazz
              Mar 20 at 10:43





              Your command worke very well ! But it only adds one space between each group of days. Can you tell me how to put 2 spaces between them ?

              – Ezzmazz
              Mar 20 at 10:43













              Change print "" with print "n"

              – Sonny
              Mar 20 at 11:13





              Change print "" with print "n"

              – Sonny
              Mar 20 at 11:13













              1














              Just pipe the output of grep to



              perl -ape 'print "n" if $previous and $previous ne $F[0]; $previous = $F[0]'



              • -p reads the input line by line and prints each line after processing


              • -a splits each input line into the @F array





              share|improve this answer



























                1














                Just pipe the output of grep to



                perl -ape 'print "n" if $previous and $previous ne $F[0]; $previous = $F[0]'



                • -p reads the input line by line and prints each line after processing


                • -a splits each input line into the @F array





                share|improve this answer

























                  1












                  1








                  1







                  Just pipe the output of grep to



                  perl -ape 'print "n" if $previous and $previous ne $F[0]; $previous = $F[0]'



                  • -p reads the input line by line and prints each line after processing


                  • -a splits each input line into the @F array





                  share|improve this answer













                  Just pipe the output of grep to



                  perl -ape 'print "n" if $previous and $previous ne $F[0]; $previous = $F[0]'



                  • -p reads the input line by line and prints each line after processing


                  • -a splits each input line into the @F array






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 8 at 19:02









                  chorobachoroba

                  160k14142211




                  160k14142211





















                      0














                      In awk could you please try following.



                      your_grep_command | awk 'prev!=$1 && prevprint "" prev=$1;print' 




                      Since OP has NOT provided samples so couldn't test it, could you please try to run directly this command? In spite of passing grep output to another command once and let us know then.



                      awk 'FNR==NRa[$0];next prev!=$1print "" ($0 in a);prev=$1' daysfile.csv <(sort -k1 myothercsv.csv)





                      share|improve this answer

























                      • @Ezzmazz, could you please check this solution once and let me now if this helps you?

                        – RavinderSingh13
                        Mar 9 at 12:18















                      0














                      In awk could you please try following.



                      your_grep_command | awk 'prev!=$1 && prevprint "" prev=$1;print' 




                      Since OP has NOT provided samples so couldn't test it, could you please try to run directly this command? In spite of passing grep output to another command once and let us know then.



                      awk 'FNR==NRa[$0];next prev!=$1print "" ($0 in a);prev=$1' daysfile.csv <(sort -k1 myothercsv.csv)





                      share|improve this answer

























                      • @Ezzmazz, could you please check this solution once and let me now if this helps you?

                        – RavinderSingh13
                        Mar 9 at 12:18













                      0












                      0








                      0







                      In awk could you please try following.



                      your_grep_command | awk 'prev!=$1 && prevprint "" prev=$1;print' 




                      Since OP has NOT provided samples so couldn't test it, could you please try to run directly this command? In spite of passing grep output to another command once and let us know then.



                      awk 'FNR==NRa[$0];next prev!=$1print "" ($0 in a);prev=$1' daysfile.csv <(sort -k1 myothercsv.csv)





                      share|improve this answer















                      In awk could you please try following.



                      your_grep_command | awk 'prev!=$1 && prevprint "" prev=$1;print' 




                      Since OP has NOT provided samples so couldn't test it, could you please try to run directly this command? In spite of passing grep output to another command once and let us know then.



                      awk 'FNR==NRa[$0];next prev!=$1print "" ($0 in a);prev=$1' daysfile.csv <(sort -k1 myothercsv.csv)






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Mar 8 at 19:14

























                      answered Mar 8 at 19:08









                      RavinderSingh13RavinderSingh13

                      30.9k41639




                      30.9k41639












                      • @Ezzmazz, could you please check this solution once and let me now if this helps you?

                        – RavinderSingh13
                        Mar 9 at 12:18

















                      • @Ezzmazz, could you please check this solution once and let me now if this helps you?

                        – RavinderSingh13
                        Mar 9 at 12:18
















                      @Ezzmazz, could you please check this solution once and let me now if this helps you?

                      – RavinderSingh13
                      Mar 9 at 12:18





                      @Ezzmazz, could you please check this solution once and let me now if this helps you?

                      – RavinderSingh13
                      Mar 9 at 12:18











                      0














                      I'm not sure how grep -wf daysfile.csv myothercsv.csv is working for you as you described. The data in myothercsv.csv must already be sorted by days of the week, since the grep command would simply print any line that has any matching word in the daysfile.csv as they are ordered.



                      If you want to search for each word in the daysfile.csv sequentially, then you probably want following:



                      cat daysfile.csv | while read line; do grep "$line" myothercsv.csv; done


                      Then you can apply the other answers here that refer to adding blank lines (when a different first word is detected) to the output.



                      Also, a different way to do this is to insert a blank line into myothercsv file, and insert ^$ lines to your daysfile. Here's an example, notice the first line in myothercsv file is a blank.



                      $ cat daysfile.csv
                      mon
                      ^$
                      tue
                      ^$
                      wed
                      ^$

                      $ cat myothercsv.csv

                      mon,1
                      tue,2
                      wed,3
                      mon,4
                      tue,5
                      wed,6

                      $ cat daysfile.csv | while read line; do grep "$line" myothercsv.csv; done
                      mon,1
                      mon,4

                      tue,2
                      tue,5

                      wed,3
                      wed,6





                      share|improve this answer





























                        0














                        I'm not sure how grep -wf daysfile.csv myothercsv.csv is working for you as you described. The data in myothercsv.csv must already be sorted by days of the week, since the grep command would simply print any line that has any matching word in the daysfile.csv as they are ordered.



                        If you want to search for each word in the daysfile.csv sequentially, then you probably want following:



                        cat daysfile.csv | while read line; do grep "$line" myothercsv.csv; done


                        Then you can apply the other answers here that refer to adding blank lines (when a different first word is detected) to the output.



                        Also, a different way to do this is to insert a blank line into myothercsv file, and insert ^$ lines to your daysfile. Here's an example, notice the first line in myothercsv file is a blank.



                        $ cat daysfile.csv
                        mon
                        ^$
                        tue
                        ^$
                        wed
                        ^$

                        $ cat myothercsv.csv

                        mon,1
                        tue,2
                        wed,3
                        mon,4
                        tue,5
                        wed,6

                        $ cat daysfile.csv | while read line; do grep "$line" myothercsv.csv; done
                        mon,1
                        mon,4

                        tue,2
                        tue,5

                        wed,3
                        wed,6





                        share|improve this answer



























                          0












                          0








                          0







                          I'm not sure how grep -wf daysfile.csv myothercsv.csv is working for you as you described. The data in myothercsv.csv must already be sorted by days of the week, since the grep command would simply print any line that has any matching word in the daysfile.csv as they are ordered.



                          If you want to search for each word in the daysfile.csv sequentially, then you probably want following:



                          cat daysfile.csv | while read line; do grep "$line" myothercsv.csv; done


                          Then you can apply the other answers here that refer to adding blank lines (when a different first word is detected) to the output.



                          Also, a different way to do this is to insert a blank line into myothercsv file, and insert ^$ lines to your daysfile. Here's an example, notice the first line in myothercsv file is a blank.



                          $ cat daysfile.csv
                          mon
                          ^$
                          tue
                          ^$
                          wed
                          ^$

                          $ cat myothercsv.csv

                          mon,1
                          tue,2
                          wed,3
                          mon,4
                          tue,5
                          wed,6

                          $ cat daysfile.csv | while read line; do grep "$line" myothercsv.csv; done
                          mon,1
                          mon,4

                          tue,2
                          tue,5

                          wed,3
                          wed,6





                          share|improve this answer















                          I'm not sure how grep -wf daysfile.csv myothercsv.csv is working for you as you described. The data in myothercsv.csv must already be sorted by days of the week, since the grep command would simply print any line that has any matching word in the daysfile.csv as they are ordered.



                          If you want to search for each word in the daysfile.csv sequentially, then you probably want following:



                          cat daysfile.csv | while read line; do grep "$line" myothercsv.csv; done


                          Then you can apply the other answers here that refer to adding blank lines (when a different first word is detected) to the output.



                          Also, a different way to do this is to insert a blank line into myothercsv file, and insert ^$ lines to your daysfile. Here's an example, notice the first line in myothercsv file is a blank.



                          $ cat daysfile.csv
                          mon
                          ^$
                          tue
                          ^$
                          wed
                          ^$

                          $ cat myothercsv.csv

                          mon,1
                          tue,2
                          wed,3
                          mon,4
                          tue,5
                          wed,6

                          $ cat daysfile.csv | while read line; do grep "$line" myothercsv.csv; done
                          mon,1
                          mon,4

                          tue,2
                          tue,5

                          wed,3
                          wed,6






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 8 at 20:08

























                          answered Mar 8 at 19:53









                          fluflu

                          486411




                          486411



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • 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%2fstackoverflow.com%2fquestions%2f55069384%2fspace-with-grep%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

                              Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                              Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                              Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved