“less” (linux) get/go-to X offset in file












7















I open a big file with this command:
less +G /var/log/blah/file.log



Now when I find the desired info I'd like to know its exact offset in this file, so later I can open that file again and return to that exact place.



So there is the "%X" command which will take me to % inside the file, in offset terms (and not lines!). It's fine, but I'd really love to be able to move to exact, numeric, offset in the file.



What is the command to get the current offset?
And what is the command to move to a specific offset?



And if I'm at that already, how do I get the current offset in percent? (to be used with the "%" command).



Note that I know of marks. They aren't what I'm looking for.










share|improve this question



























    7















    I open a big file with this command:
    less +G /var/log/blah/file.log



    Now when I find the desired info I'd like to know its exact offset in this file, so later I can open that file again and return to that exact place.



    So there is the "%X" command which will take me to % inside the file, in offset terms (and not lines!). It's fine, but I'd really love to be able to move to exact, numeric, offset in the file.



    What is the command to get the current offset?
    And what is the command to move to a specific offset?



    And if I'm at that already, how do I get the current offset in percent? (to be used with the "%" command).



    Note that I know of marks. They aren't what I'm looking for.










    share|improve this question

























      7












      7








      7








      I open a big file with this command:
      less +G /var/log/blah/file.log



      Now when I find the desired info I'd like to know its exact offset in this file, so later I can open that file again and return to that exact place.



      So there is the "%X" command which will take me to % inside the file, in offset terms (and not lines!). It's fine, but I'd really love to be able to move to exact, numeric, offset in the file.



      What is the command to get the current offset?
      And what is the command to move to a specific offset?



      And if I'm at that already, how do I get the current offset in percent? (to be used with the "%" command).



      Note that I know of marks. They aren't what I'm looking for.










      share|improve this question














      I open a big file with this command:
      less +G /var/log/blah/file.log



      Now when I find the desired info I'd like to know its exact offset in this file, so later I can open that file again and return to that exact place.



      So there is the "%X" command which will take me to % inside the file, in offset terms (and not lines!). It's fine, but I'd really love to be able to move to exact, numeric, offset in the file.



      What is the command to get the current offset?
      And what is the command to move to a specific offset?



      And if I'm at that already, how do I get the current offset in percent? (to be used with the "%" command).



      Note that I know of marks. They aren't what I'm looking for.







      linux less






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 28 '11 at 11:06









      PoniPoni

      353412




      353412






















          3 Answers
          3






          active

          oldest

          votes


















          14














          Got part of my question from here:



          100g to go to the 100th line
          50p to go to 50% into the file
          100P to go to the line containing 100th byte



          To determine the current line number or byte offset, use Ctrl+g.






          share|improve this answer





















          • 3





            Found it: Ctrl+g !

            – Poni
            Jan 16 '12 at 14:15











          • For very large files, you may also want to invoke less with -n to avoid calculating line numbers.

            – Miles
            Jan 9 at 1:47



















          0














          With my version the lines currently on screen are displayed at the bottom.



          To go to a specific line you can type <number>G.






          share|improve this answer
























          • Since the file is very big (more than GB) I'm not even using lines. I need to deal with offset within the file only. Thanks Rob

            – Poni
            Dec 28 '11 at 11:14



















          0














          Assuming that by 'offset' you mean byte-offset (as opposed to characters), you can use the vi editor and search for the pattern with



          /pattern


          hit Enter. Repeated fwd searching for the same pattern can be repeated with



          /


          hit Enter.



          Cursor position's line and column numbers are displayed at bottom right, so to go to a particular line, say 201, and column, say 17, you type



          201G17l


          That's 201, capital G, 17, lowercase l



          If your file consists of only 1 line with your pattern at offset 10125, then open it with vi



          $ vi my_massive_file


          and type



          :goto 10125





          share|improve this answer
























          • i noticed after posting that your file is > 1GB and that is probably why you are using less. vi should be able to handle it if you have enough memory

            – venzen
            Dec 28 '11 at 12:15











          • Yea, it opens way too slow with vi/m. Not good for me. And yes also to your assumption; I mean "offset" as in bytes within the file.

            – Poni
            Dec 28 '11 at 12:52













          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          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%2fsuperuser.com%2fquestions%2f372253%2fless-linux-get-go-to-x-offset-in-file%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          14














          Got part of my question from here:



          100g to go to the 100th line
          50p to go to 50% into the file
          100P to go to the line containing 100th byte



          To determine the current line number or byte offset, use Ctrl+g.






          share|improve this answer





















          • 3





            Found it: Ctrl+g !

            – Poni
            Jan 16 '12 at 14:15











          • For very large files, you may also want to invoke less with -n to avoid calculating line numbers.

            – Miles
            Jan 9 at 1:47
















          14














          Got part of my question from here:



          100g to go to the 100th line
          50p to go to 50% into the file
          100P to go to the line containing 100th byte



          To determine the current line number or byte offset, use Ctrl+g.






          share|improve this answer





















          • 3





            Found it: Ctrl+g !

            – Poni
            Jan 16 '12 at 14:15











          • For very large files, you may also want to invoke less with -n to avoid calculating line numbers.

            – Miles
            Jan 9 at 1:47














          14












          14








          14







          Got part of my question from here:



          100g to go to the 100th line
          50p to go to 50% into the file
          100P to go to the line containing 100th byte



          To determine the current line number or byte offset, use Ctrl+g.






          share|improve this answer















          Got part of my question from here:



          100g to go to the 100th line
          50p to go to 50% into the file
          100P to go to the line containing 100th byte



          To determine the current line number or byte offset, use Ctrl+g.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 9 at 2:07









          Miles

          30129




          30129










          answered Dec 29 '11 at 13:25









          PoniPoni

          353412




          353412








          • 3





            Found it: Ctrl+g !

            – Poni
            Jan 16 '12 at 14:15











          • For very large files, you may also want to invoke less with -n to avoid calculating line numbers.

            – Miles
            Jan 9 at 1:47














          • 3





            Found it: Ctrl+g !

            – Poni
            Jan 16 '12 at 14:15











          • For very large files, you may also want to invoke less with -n to avoid calculating line numbers.

            – Miles
            Jan 9 at 1:47








          3




          3





          Found it: Ctrl+g !

          – Poni
          Jan 16 '12 at 14:15





          Found it: Ctrl+g !

          – Poni
          Jan 16 '12 at 14:15













          For very large files, you may also want to invoke less with -n to avoid calculating line numbers.

          – Miles
          Jan 9 at 1:47





          For very large files, you may also want to invoke less with -n to avoid calculating line numbers.

          – Miles
          Jan 9 at 1:47













          0














          With my version the lines currently on screen are displayed at the bottom.



          To go to a specific line you can type <number>G.






          share|improve this answer
























          • Since the file is very big (more than GB) I'm not even using lines. I need to deal with offset within the file only. Thanks Rob

            – Poni
            Dec 28 '11 at 11:14
















          0














          With my version the lines currently on screen are displayed at the bottom.



          To go to a specific line you can type <number>G.






          share|improve this answer
























          • Since the file is very big (more than GB) I'm not even using lines. I need to deal with offset within the file only. Thanks Rob

            – Poni
            Dec 28 '11 at 11:14














          0












          0








          0







          With my version the lines currently on screen are displayed at the bottom.



          To go to a specific line you can type <number>G.






          share|improve this answer













          With my version the lines currently on screen are displayed at the bottom.



          To go to a specific line you can type <number>G.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 28 '11 at 11:10









          Rob WoutersRob Wouters

          35614




          35614













          • Since the file is very big (more than GB) I'm not even using lines. I need to deal with offset within the file only. Thanks Rob

            – Poni
            Dec 28 '11 at 11:14



















          • Since the file is very big (more than GB) I'm not even using lines. I need to deal with offset within the file only. Thanks Rob

            – Poni
            Dec 28 '11 at 11:14

















          Since the file is very big (more than GB) I'm not even using lines. I need to deal with offset within the file only. Thanks Rob

          – Poni
          Dec 28 '11 at 11:14





          Since the file is very big (more than GB) I'm not even using lines. I need to deal with offset within the file only. Thanks Rob

          – Poni
          Dec 28 '11 at 11:14











          0














          Assuming that by 'offset' you mean byte-offset (as opposed to characters), you can use the vi editor and search for the pattern with



          /pattern


          hit Enter. Repeated fwd searching for the same pattern can be repeated with



          /


          hit Enter.



          Cursor position's line and column numbers are displayed at bottom right, so to go to a particular line, say 201, and column, say 17, you type



          201G17l


          That's 201, capital G, 17, lowercase l



          If your file consists of only 1 line with your pattern at offset 10125, then open it with vi



          $ vi my_massive_file


          and type



          :goto 10125





          share|improve this answer
























          • i noticed after posting that your file is > 1GB and that is probably why you are using less. vi should be able to handle it if you have enough memory

            – venzen
            Dec 28 '11 at 12:15











          • Yea, it opens way too slow with vi/m. Not good for me. And yes also to your assumption; I mean "offset" as in bytes within the file.

            – Poni
            Dec 28 '11 at 12:52


















          0














          Assuming that by 'offset' you mean byte-offset (as opposed to characters), you can use the vi editor and search for the pattern with



          /pattern


          hit Enter. Repeated fwd searching for the same pattern can be repeated with



          /


          hit Enter.



          Cursor position's line and column numbers are displayed at bottom right, so to go to a particular line, say 201, and column, say 17, you type



          201G17l


          That's 201, capital G, 17, lowercase l



          If your file consists of only 1 line with your pattern at offset 10125, then open it with vi



          $ vi my_massive_file


          and type



          :goto 10125





          share|improve this answer
























          • i noticed after posting that your file is > 1GB and that is probably why you are using less. vi should be able to handle it if you have enough memory

            – venzen
            Dec 28 '11 at 12:15











          • Yea, it opens way too slow with vi/m. Not good for me. And yes also to your assumption; I mean "offset" as in bytes within the file.

            – Poni
            Dec 28 '11 at 12:52
















          0












          0








          0







          Assuming that by 'offset' you mean byte-offset (as opposed to characters), you can use the vi editor and search for the pattern with



          /pattern


          hit Enter. Repeated fwd searching for the same pattern can be repeated with



          /


          hit Enter.



          Cursor position's line and column numbers are displayed at bottom right, so to go to a particular line, say 201, and column, say 17, you type



          201G17l


          That's 201, capital G, 17, lowercase l



          If your file consists of only 1 line with your pattern at offset 10125, then open it with vi



          $ vi my_massive_file


          and type



          :goto 10125





          share|improve this answer













          Assuming that by 'offset' you mean byte-offset (as opposed to characters), you can use the vi editor and search for the pattern with



          /pattern


          hit Enter. Repeated fwd searching for the same pattern can be repeated with



          /


          hit Enter.



          Cursor position's line and column numbers are displayed at bottom right, so to go to a particular line, say 201, and column, say 17, you type



          201G17l


          That's 201, capital G, 17, lowercase l



          If your file consists of only 1 line with your pattern at offset 10125, then open it with vi



          $ vi my_massive_file


          and type



          :goto 10125






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 28 '11 at 12:12









          venzenvenzen

          31915




          31915













          • i noticed after posting that your file is > 1GB and that is probably why you are using less. vi should be able to handle it if you have enough memory

            – venzen
            Dec 28 '11 at 12:15











          • Yea, it opens way too slow with vi/m. Not good for me. And yes also to your assumption; I mean "offset" as in bytes within the file.

            – Poni
            Dec 28 '11 at 12:52





















          • i noticed after posting that your file is > 1GB and that is probably why you are using less. vi should be able to handle it if you have enough memory

            – venzen
            Dec 28 '11 at 12:15











          • Yea, it opens way too slow with vi/m. Not good for me. And yes also to your assumption; I mean "offset" as in bytes within the file.

            – Poni
            Dec 28 '11 at 12:52



















          i noticed after posting that your file is > 1GB and that is probably why you are using less. vi should be able to handle it if you have enough memory

          – venzen
          Dec 28 '11 at 12:15





          i noticed after posting that your file is > 1GB and that is probably why you are using less. vi should be able to handle it if you have enough memory

          – venzen
          Dec 28 '11 at 12:15













          Yea, it opens way too slow with vi/m. Not good for me. And yes also to your assumption; I mean "offset" as in bytes within the file.

          – Poni
          Dec 28 '11 at 12:52







          Yea, it opens way too slow with vi/m. Not good for me. And yes also to your assumption; I mean "offset" as in bytes within the file.

          – Poni
          Dec 28 '11 at 12:52




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • 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%2fsuperuser.com%2fquestions%2f372253%2fless-linux-get-go-to-x-offset-in-file%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

          Probability when a professor distributes a quiz and homework assignment to a class of n students.

          Aardman Animations

          Are they similar matrix