print multiple words separated by space

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











up vote
1
down vote

favorite












I have a text file and the data inside has format like (name age country):



michael jordans 25 US
adam smith 30 UK
chris wood ABC 22 Aus


if I use command: cat text.txt | awk 'print $1' --> it will print:



michael
adam
chris


but I want to print the full name:



michael jordans
adam smith
chris wood ABC


so please help me this, which command should I use ?



If we need, we can change the format data like:



michael jordans|25|US
adam smith|30|UK
chris wood ABC|22|Aus









share|improve this question



























    up vote
    1
    down vote

    favorite












    I have a text file and the data inside has format like (name age country):



    michael jordans 25 US
    adam smith 30 UK
    chris wood ABC 22 Aus


    if I use command: cat text.txt | awk 'print $1' --> it will print:



    michael
    adam
    chris


    but I want to print the full name:



    michael jordans
    adam smith
    chris wood ABC


    so please help me this, which command should I use ?



    If we need, we can change the format data like:



    michael jordans|25|US
    adam smith|30|UK
    chris wood ABC|22|Aus









    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have a text file and the data inside has format like (name age country):



      michael jordans 25 US
      adam smith 30 UK
      chris wood ABC 22 Aus


      if I use command: cat text.txt | awk 'print $1' --> it will print:



      michael
      adam
      chris


      but I want to print the full name:



      michael jordans
      adam smith
      chris wood ABC


      so please help me this, which command should I use ?



      If we need, we can change the format data like:



      michael jordans|25|US
      adam smith|30|UK
      chris wood ABC|22|Aus









      share|improve this question















      I have a text file and the data inside has format like (name age country):



      michael jordans 25 US
      adam smith 30 UK
      chris wood ABC 22 Aus


      if I use command: cat text.txt | awk 'print $1' --> it will print:



      michael
      adam
      chris


      but I want to print the full name:



      michael jordans
      adam smith
      chris wood ABC


      so please help me this, which command should I use ?



      If we need, we can change the format data like:



      michael jordans|25|US
      adam smith|30|UK
      chris wood ABC|22|Aus






      text-processing awk printf






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 22 at 12:13









      Jeff Schaller

      33.3k849111




      33.3k849111










      asked Jun 15 '16 at 3:31









      user175124

      61




      61




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          sed 's/^([^0-9]*).*/1/' text.tex


          This assumes that the name does not contain a numeric character and the field just after the name starts with a number.



          When you separate the fields by |, it can be done by



          sed 's/^([^|]*).*/1/' text.tex


          or if you like awk, you can do



          awk -F| 'print $1' text.tex





          share|improve this answer





























            up vote
            0
            down vote













            If you change the file to have proper field separators, like |, the solution is trivial:



            awk -F'|' 'print $1' input_file


            If you use blanks, which also occur within the intended fields, instead of proper field separators, then you can do something like this:



             awk ' a = $1; for (i=2; i <= NF-2; i++) a = a " " $i; print a; ' input_file





            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%2f289811%2fprint-multiple-words-separated-by-space%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













              sed 's/^([^0-9]*).*/1/' text.tex


              This assumes that the name does not contain a numeric character and the field just after the name starts with a number.



              When you separate the fields by |, it can be done by



              sed 's/^([^|]*).*/1/' text.tex


              or if you like awk, you can do



              awk -F| 'print $1' text.tex





              share|improve this answer


























                up vote
                1
                down vote













                sed 's/^([^0-9]*).*/1/' text.tex


                This assumes that the name does not contain a numeric character and the field just after the name starts with a number.



                When you separate the fields by |, it can be done by



                sed 's/^([^|]*).*/1/' text.tex


                or if you like awk, you can do



                awk -F| 'print $1' text.tex





                share|improve this answer
























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  sed 's/^([^0-9]*).*/1/' text.tex


                  This assumes that the name does not contain a numeric character and the field just after the name starts with a number.



                  When you separate the fields by |, it can be done by



                  sed 's/^([^|]*).*/1/' text.tex


                  or if you like awk, you can do



                  awk -F| 'print $1' text.tex





                  share|improve this answer














                  sed 's/^([^0-9]*).*/1/' text.tex


                  This assumes that the name does not contain a numeric character and the field just after the name starts with a number.



                  When you separate the fields by |, it can be done by



                  sed 's/^([^|]*).*/1/' text.tex


                  or if you like awk, you can do



                  awk -F| 'print $1' text.tex






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jun 15 '16 at 3:49

























                  answered Jun 15 '16 at 3:43









                  unxnut

                  3,4202918




                  3,4202918






















                      up vote
                      0
                      down vote













                      If you change the file to have proper field separators, like |, the solution is trivial:



                      awk -F'|' 'print $1' input_file


                      If you use blanks, which also occur within the intended fields, instead of proper field separators, then you can do something like this:



                       awk ' a = $1; for (i=2; i <= NF-2; i++) a = a " " $i; print a; ' input_file





                      share|improve this answer
























                        up vote
                        0
                        down vote













                        If you change the file to have proper field separators, like |, the solution is trivial:



                        awk -F'|' 'print $1' input_file


                        If you use blanks, which also occur within the intended fields, instead of proper field separators, then you can do something like this:



                         awk ' a = $1; for (i=2; i <= NF-2; i++) a = a " " $i; print a; ' input_file





                        share|improve this answer






















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          If you change the file to have proper field separators, like |, the solution is trivial:



                          awk -F'|' 'print $1' input_file


                          If you use blanks, which also occur within the intended fields, instead of proper field separators, then you can do something like this:



                           awk ' a = $1; for (i=2; i <= NF-2; i++) a = a " " $i; print a; ' input_file





                          share|improve this answer












                          If you change the file to have proper field separators, like |, the solution is trivial:



                          awk -F'|' 'print $1' input_file


                          If you use blanks, which also occur within the intended fields, instead of proper field separators, then you can do something like this:



                           awk ' a = $1; for (i=2; i <= NF-2; i++) a = a " " $i; print a; ' input_file






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jun 15 '16 at 5:51









                          Michael Vehrs

                          2,18037




                          2,18037



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f289811%2fprint-multiple-words-separated-by-space%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?