How can I copy the records of the file “/etc/bashrc” that have the “TMOUT” string except those containing the “read-only” string, to the file?

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











up vote
0
down vote

favorite












my question is about centos file copy



How can I copy the records of the file “/etc/bashrc” that have the “TMOUT” string except those containing the “read-only” string, to the file?










share|improve this question



























    up vote
    0
    down vote

    favorite












    my question is about centos file copy



    How can I copy the records of the file “/etc/bashrc” that have the “TMOUT” string except those containing the “read-only” string, to the file?










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      my question is about centos file copy



      How can I copy the records of the file “/etc/bashrc” that have the “TMOUT” string except those containing the “read-only” string, to the file?










      share|improve this question















      my question is about centos file copy



      How can I copy the records of the file “/etc/bashrc” that have the “TMOUT” string except those containing the “read-only” string, to the file?







      text-processing






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 25 '17 at 16:16









      Kusalananda

      106k14209327




      106k14209327










      asked Sep 25 '17 at 16:00









      JaxTeller

      62




      62




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          grep 'TMOUT' /etc/bashrc | grep -v 'read-only' >output


          This first extracts all lines from /etc/bashrc that contains the string TMOUT. The second grep removes all of those lines that also contain the string read-only. The output is saved to the file output.






          share|improve this answer





























            up vote
            0
            down vote













            With just one command:



            awk '/TMOUT/ && !/read-only/' < /etc/bashrc > output


            Or:



            sed '/TMOUT/!d; /read-only/d' < /etc/bashrc > output


            (delete the lines that don't (!) contain TMOUT and those that contain read-only).



            Those also have the advantage of not clobbering the output file if /etc/bashrc can't be opened.






            share|improve this answer




















              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',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              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%2f394343%2fhow-can-i-copy-the-records-of-the-file-etc-bashrc-that-have-the-tmout-strin%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              1
              down vote



              accepted










              grep 'TMOUT' /etc/bashrc | grep -v 'read-only' >output


              This first extracts all lines from /etc/bashrc that contains the string TMOUT. The second grep removes all of those lines that also contain the string read-only. The output is saved to the file output.






              share|improve this answer


























                up vote
                1
                down vote



                accepted










                grep 'TMOUT' /etc/bashrc | grep -v 'read-only' >output


                This first extracts all lines from /etc/bashrc that contains the string TMOUT. The second grep removes all of those lines that also contain the string read-only. The output is saved to the file output.






                share|improve this answer
























                  up vote
                  1
                  down vote



                  accepted







                  up vote
                  1
                  down vote



                  accepted






                  grep 'TMOUT' /etc/bashrc | grep -v 'read-only' >output


                  This first extracts all lines from /etc/bashrc that contains the string TMOUT. The second grep removes all of those lines that also contain the string read-only. The output is saved to the file output.






                  share|improve this answer














                  grep 'TMOUT' /etc/bashrc | grep -v 'read-only' >output


                  This first extracts all lines from /etc/bashrc that contains the string TMOUT. The second grep removes all of those lines that also contain the string read-only. The output is saved to the file output.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Sep 25 '17 at 16:24

























                  answered Sep 25 '17 at 16:15









                  Kusalananda

                  106k14209327




                  106k14209327






















                      up vote
                      0
                      down vote













                      With just one command:



                      awk '/TMOUT/ && !/read-only/' < /etc/bashrc > output


                      Or:



                      sed '/TMOUT/!d; /read-only/d' < /etc/bashrc > output


                      (delete the lines that don't (!) contain TMOUT and those that contain read-only).



                      Those also have the advantage of not clobbering the output file if /etc/bashrc can't be opened.






                      share|improve this answer
























                        up vote
                        0
                        down vote













                        With just one command:



                        awk '/TMOUT/ && !/read-only/' < /etc/bashrc > output


                        Or:



                        sed '/TMOUT/!d; /read-only/d' < /etc/bashrc > output


                        (delete the lines that don't (!) contain TMOUT and those that contain read-only).



                        Those also have the advantage of not clobbering the output file if /etc/bashrc can't be opened.






                        share|improve this answer






















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          With just one command:



                          awk '/TMOUT/ && !/read-only/' < /etc/bashrc > output


                          Or:



                          sed '/TMOUT/!d; /read-only/d' < /etc/bashrc > output


                          (delete the lines that don't (!) contain TMOUT and those that contain read-only).



                          Those also have the advantage of not clobbering the output file if /etc/bashrc can't be opened.






                          share|improve this answer












                          With just one command:



                          awk '/TMOUT/ && !/read-only/' < /etc/bashrc > output


                          Or:



                          sed '/TMOUT/!d; /read-only/d' < /etc/bashrc > output


                          (delete the lines that don't (!) contain TMOUT and those that contain read-only).



                          Those also have the advantage of not clobbering the output file if /etc/bashrc can't be opened.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Sep 25 '17 at 16:28









                          Stéphane Chazelas

                          284k53523860




                          284k53523860



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f394343%2fhow-can-i-copy-the-records-of-the-file-etc-bashrc-that-have-the-tmout-strin%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

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

                              Christian Cage

                              How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?