Changing text on a file using scripts [duplicate]












0















This question already has an answer here:




  • Find and replace text within a file using commands

    7 answers




I want to change the PASS_MIN_DAYS = (whatever value is set) to PASS_MIN_DAYS = 15 using a script.The file it's in is /etc/login.defs.










share|improve this question















marked as duplicate by wjandrea, Sergiy Kolodyazhnyy bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 6 at 23:37


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




















    0















    This question already has an answer here:




    • Find and replace text within a file using commands

      7 answers




    I want to change the PASS_MIN_DAYS = (whatever value is set) to PASS_MIN_DAYS = 15 using a script.The file it's in is /etc/login.defs.










    share|improve this question















    marked as duplicate by wjandrea, Sergiy Kolodyazhnyy bash
    Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Dec 6 at 23:37


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















      0












      0








      0








      This question already has an answer here:




      • Find and replace text within a file using commands

        7 answers




      I want to change the PASS_MIN_DAYS = (whatever value is set) to PASS_MIN_DAYS = 15 using a script.The file it's in is /etc/login.defs.










      share|improve this question
















      This question already has an answer here:




      • Find and replace text within a file using commands

        7 answers




      I want to change the PASS_MIN_DAYS = (whatever value is set) to PASS_MIN_DAYS = 15 using a script.The file it's in is /etc/login.defs.





      This question already has an answer here:




      • Find and replace text within a file using commands

        7 answers








      bash scripts text-processing text






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 6 at 20:35









      dessert

      21.9k55997




      21.9k55997










      asked Dec 6 at 20:00









      Ivan Mikhaylov

      11




      11




      marked as duplicate by wjandrea, Sergiy Kolodyazhnyy bash
      Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Dec 6 at 23:37


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by wjandrea, Sergiy Kolodyazhnyy bash
      Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Dec 6 at 23:37


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























          1 Answer
          1






          active

          oldest

          votes


















          3














          I’d use sed like this:



          sed '/^PASS_MIN_DAYS/s/[0-9]+/15/'


          This replaces the number in the line beginning with “PASS_MIN_DAYS” with 15. To edit the file in place leaving a backup with the .bak extension, use the following command. By default you need root access to edit the file.



          sed -i.bak '/^PASS_MIN_DAYS/s/[0-9]+/15/' /etc/login.defs





          share|improve this answer






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            I’d use sed like this:



            sed '/^PASS_MIN_DAYS/s/[0-9]+/15/'


            This replaces the number in the line beginning with “PASS_MIN_DAYS” with 15. To edit the file in place leaving a backup with the .bak extension, use the following command. By default you need root access to edit the file.



            sed -i.bak '/^PASS_MIN_DAYS/s/[0-9]+/15/' /etc/login.defs





            share|improve this answer




























              3














              I’d use sed like this:



              sed '/^PASS_MIN_DAYS/s/[0-9]+/15/'


              This replaces the number in the line beginning with “PASS_MIN_DAYS” with 15. To edit the file in place leaving a backup with the .bak extension, use the following command. By default you need root access to edit the file.



              sed -i.bak '/^PASS_MIN_DAYS/s/[0-9]+/15/' /etc/login.defs





              share|improve this answer


























                3












                3








                3






                I’d use sed like this:



                sed '/^PASS_MIN_DAYS/s/[0-9]+/15/'


                This replaces the number in the line beginning with “PASS_MIN_DAYS” with 15. To edit the file in place leaving a backup with the .bak extension, use the following command. By default you need root access to edit the file.



                sed -i.bak '/^PASS_MIN_DAYS/s/[0-9]+/15/' /etc/login.defs





                share|improve this answer














                I’d use sed like this:



                sed '/^PASS_MIN_DAYS/s/[0-9]+/15/'


                This replaces the number in the line beginning with “PASS_MIN_DAYS” with 15. To edit the file in place leaving a backup with the .bak extension, use the following command. By default you need root access to edit the file.



                sed -i.bak '/^PASS_MIN_DAYS/s/[0-9]+/15/' /etc/login.defs






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 6 at 20:31

























                answered Dec 6 at 20:16









                dessert

                21.9k55997




                21.9k55997















                    Popular posts from this blog

                    Quarter-circle Tiles

                    build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

                    Mont Emei