Loading ...
Sorry, an error occurred while loading the content.

Selective portion of a file

Expand Messages
  • p_s_rathi
    Hello All, Is there any way through which, some selected portion of a file can be displayed. The cat command displays the whole file.While I am interested in
    Message 1 of 6 , Jul 1, 2003
    • 0 Attachment
      Hello All,

      Is there any way through which, some selected portion of a file can
      be displayed. The cat command displays the whole file.While I am
      interested in extracting selective portion of it.
      Please let me know if anyone knows.
      Thanks,
      Priti
    • Satish
      You can use following command. cat | grep Regards, Satish
      Message 2 of 6 , Jul 1, 2003
      • 0 Attachment
        You can use following command.

        cat <file_name> | grep <content u want to search>

        Regards,
        Satish

        p_s_rathi wrote:

        >Hello All,
        >
        >Is there any way through which, some selected portion of a file can
        >be displayed. The cat command displays the whole file.While I am
        >interested in extracting selective portion of it.
        >Please let me know if anyone knows.
        >Thanks,
        >Priti
        >
        >
        >
        >To unsubscribe from this list, please email LINUX_Newbies-unsubscribe@yahoogroups.com & you will be removed.
        >
        >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
        >
        >
        >
        >
      • p_s_rathi
        Yeah thats true, but it will display all occurences of particular string in file. Is it possible to display whole function s code(suppose the code of main() in
        Message 3 of 6 , Jul 1, 2003
        • 0 Attachment
          Yeah thats true,
          but it will display all occurences of particular string in file.
          Is it possible to display whole function's code(suppose the code of
          main() in .c file)? any command for that?or any good editor which
          will save time for it.

          --- In LINUX_Newbies@yahoogroups.com, Satish <satish@e...> wrote:
          > You can use following command.
          >
          > cat <file_name> | grep <content u want to search>
          >
          > Regards,
          > Satish
          >
          > p_s_rathi wrote:
          >
          > >Hello All,
          > >
          > >Is there any way through which, some selected portion of a file
          can
          > >be displayed. The cat command displays the whole file.While I am
          > >interested in extracting selective portion of it.
          > >Please let me know if anyone knows.
          > >Thanks,
          > >Priti
          > >
          > >
          > >
          > >To unsubscribe from this list, please email LINUX_Newbies-
          unsubscribe@yahoogroups.com & you will be removed.
          > >
          > >Your use of Yahoo! Groups is subject to
          http://docs.yahoo.com/info/terms/
          > >
          > >
          > >
          > >
        • Satish
          Hi Priti, See in this case you need to display no. of lines. But prereq is that, you need to know how many lines you want to display after completion of
          Message 4 of 6 , Jul 1, 2003
          • 0 Attachment
            Hi Priti,

            See in this case you need to display no. of lines. But prereq is that,
            you need to know how many lines you want to display after completion of
            search.
            I dont think any IDE/Editor will support your requirement.
            Hey Please let me know if you will find some solution to your problem.

            Well, you can use VIM editor and find the loop structure through % sign.
            If you will move your cursor on "{" bracket it will show you the end of
            Code Segment i.e. next "}".

            Regards,
            Satish

            p_s_rathi wrote:

            >Yeah thats true,
            >but it will display all occurences of particular string in file.
            >Is it possible to display whole function's code(suppose the code of
            >main() in .c file)? any command for that?or any good editor which
            >will save time for it.
            >
            >--- In LINUX_Newbies@yahoogroups.com, Satish <satish@e...> wrote:
            >
            >
            >>You can use following command.
            >>
            >>cat <file_name> | grep <content u want to search>
            >>
            >>Regards,
            >>Satish
            >>
            >>p_s_rathi wrote:
            >>
            >>
            >>
            >>>Hello All,
            >>>
            >>>Is there any way through which, some selected portion of a file
            >>>
            >>>
            >can
            >
            >
            >>>be displayed. The cat command displays the whole file.While I am
            >>>interested in extracting selective portion of it.
            >>>Please let me know if anyone knows.
            >>>Thanks,
            >>>Priti
            >>>
            >>>
            >>>
            >>>To unsubscribe from this list, please email LINUX_Newbies-
            >>>
            >>>
            >unsubscribe@yahoogroups.com & you will be removed.
            >
            >
            >>>Your use of Yahoo! Groups is subject to
            >>>
            >>>
            >http://docs.yahoo.com/info/terms/
            >
            >
            >>>
            >>>
            >>>
            >>>
            >
            >
            >
            >To unsubscribe from this list, please email LINUX_Newbies-unsubscribe@yahoogroups.com & you will be removed.
            >
            >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
            >
            >
            >
            >



            [Non-text portions of this message have been removed]
          • horrorvacui@gmx.net
            On Tue, 01 Jul 2003 11:13:39 -0000 ... No. Something like that is a bit too complicated and too useless to program. You use cat to output a file to stdout, if
            Message 5 of 6 , Jul 1, 2003
            • 0 Attachment
              On Tue, 01 Jul 2003 11:13:39 -0000
              "p_s_rathi" <p_s_rathi@...> wrote:

              > Yeah thats true,
              > but it will display all occurences of particular string in file.
              > Is it possible to display whole function's code(suppose the code of
              > main() in .c file)? any command for that?or any good editor which
              > will save time for it.

              No. Something like that is a bit too complicated and too useless to
              program. You use cat to output a file to stdout, if you search for
              occurences of a string you pipe it through grep, and if you want to
              navigate in the file you open it with a viewer or a text editor. Every
              task has its tool, and it's not the cat's fault that you're using it for
              something it's not meant for. Try using less as a viewer - it lets you
              navigate in much the same way you'd do in vi.

              Cheers

              --
              Horror Vacui

              Registered Linux user #257714

              Go get yourself... counted: http://counter.li.org/
              - and keep following the GNU.
            • Cameron Simpson
              ... Well, if you know a little about your code formatting convention you can go: sed -n /^main(/,/^}/p foo.c which assumes main( will be at the start of a
              Message 6 of 6 , Jul 1, 2003
              • 0 Attachment
                On 11:13 01 Jul 2003, p_s_rathi <p_s_rathi@...> wrote:
                | Yeah thats true,
                | but it will display all occurences of particular string in file.
                | Is it possible to display whole function's code(suppose the code of
                | main() in .c file)? any command for that?or any good editor which
                | will save time for it.

                Well, if you know a little about your code formatting convention you can
                go:

                sed -n '/^main(/,/^}/p' foo.c

                which assumes "main(" will be at the start of a line and that the next
                closing } which is also at the start of a line is the end of the function.

                In general:

                sed -n '/starting-marker/,/ending-marker/p' filename...

                will do what you ask. You just have to pick suitable starting-marker and
                ending-marker patterns.

                Extremely handy. Cheers,
                --
                Cameron Simpson <cs@...> DoD#743
                http://www.cskk.ezoshosting.com/cs/

                Thus spake Kalmoth the Avenger, Kinsman of the Slain:
                "DISCLAIMER: I speak for no one who lives."
              Your message has been successfully submitted and would be delivered to recipients shortly.