Use Variable Date in Sed Command

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 margin-bottom:0;







up vote
3
down vote

favorite












I want to use sed command as below:



$ sed -n '/MONTH_TODAY DATE_YEST/,/MONTH_TODAY DATE_TODAY/p' 
/home/crmiib/TESTUSERLOG/XYZ/user.log


I can print logs using:



$ sed -n '/Jul 27/,/Jul 28/p' /home/crmiib/TESTUSERLOG/XYZ/user.log


But I want to view logs using variables instead of hard coded dates?







share|improve this question



























    up vote
    3
    down vote

    favorite












    I want to use sed command as below:



    $ sed -n '/MONTH_TODAY DATE_YEST/,/MONTH_TODAY DATE_TODAY/p' 
    /home/crmiib/TESTUSERLOG/XYZ/user.log


    I can print logs using:



    $ sed -n '/Jul 27/,/Jul 28/p' /home/crmiib/TESTUSERLOG/XYZ/user.log


    But I want to view logs using variables instead of hard coded dates?







    share|improve this question























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I want to use sed command as below:



      $ sed -n '/MONTH_TODAY DATE_YEST/,/MONTH_TODAY DATE_TODAY/p' 
      /home/crmiib/TESTUSERLOG/XYZ/user.log


      I can print logs using:



      $ sed -n '/Jul 27/,/Jul 28/p' /home/crmiib/TESTUSERLOG/XYZ/user.log


      But I want to view logs using variables instead of hard coded dates?







      share|improve this question













      I want to use sed command as below:



      $ sed -n '/MONTH_TODAY DATE_YEST/,/MONTH_TODAY DATE_TODAY/p' 
      /home/crmiib/TESTUSERLOG/XYZ/user.log


      I can print logs using:



      $ sed -n '/Jul 27/,/Jul 28/p' /home/crmiib/TESTUSERLOG/XYZ/user.log


      But I want to view logs using variables instead of hard coded dates?









      share|improve this question












      share|improve this question




      share|improve this question








      edited Jul 28 at 19:10









      slm♦

      232k65479649




      232k65479649









      asked Jul 28 at 18:28









      Hamas Rizwan

      404




      404




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          Use double quotes so the shell evaluates the variables before sed runs:



          DATE_YEST="Jul 27"
          DATE_TODAY="Jul 28"
          sed -n "/$DATE_YEST/,/$DATE_TODAY/p" /home/crmiib/TESTUSERLOG/XYZ/user.log





          share|improve this answer























          • Thanks Man.! :)
            – Hamas Rizwan
            Jul 28 at 18:59










          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%2f459077%2fuse-variable-date-in-sed-command%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote



          accepted










          Use double quotes so the shell evaluates the variables before sed runs:



          DATE_YEST="Jul 27"
          DATE_TODAY="Jul 28"
          sed -n "/$DATE_YEST/,/$DATE_TODAY/p" /home/crmiib/TESTUSERLOG/XYZ/user.log





          share|improve this answer























          • Thanks Man.! :)
            – Hamas Rizwan
            Jul 28 at 18:59














          up vote
          4
          down vote



          accepted










          Use double quotes so the shell evaluates the variables before sed runs:



          DATE_YEST="Jul 27"
          DATE_TODAY="Jul 28"
          sed -n "/$DATE_YEST/,/$DATE_TODAY/p" /home/crmiib/TESTUSERLOG/XYZ/user.log





          share|improve this answer























          • Thanks Man.! :)
            – Hamas Rizwan
            Jul 28 at 18:59












          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted






          Use double quotes so the shell evaluates the variables before sed runs:



          DATE_YEST="Jul 27"
          DATE_TODAY="Jul 28"
          sed -n "/$DATE_YEST/,/$DATE_TODAY/p" /home/crmiib/TESTUSERLOG/XYZ/user.log





          share|improve this answer















          Use double quotes so the shell evaluates the variables before sed runs:



          DATE_YEST="Jul 27"
          DATE_TODAY="Jul 28"
          sed -n "/$DATE_YEST/,/$DATE_TODAY/p" /home/crmiib/TESTUSERLOG/XYZ/user.log






          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited Jul 28 at 18:41


























          answered Jul 28 at 18:38









          JRFerguson

          9,06532228




          9,06532228











          • Thanks Man.! :)
            – Hamas Rizwan
            Jul 28 at 18:59
















          • Thanks Man.! :)
            – Hamas Rizwan
            Jul 28 at 18:59















          Thanks Man.! :)
          – Hamas Rizwan
          Jul 28 at 18:59




          Thanks Man.! :)
          – Hamas Rizwan
          Jul 28 at 18:59












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f459077%2fuse-variable-date-in-sed-command%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?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?