Delete string file after 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 many log files generated like the bellow:



Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George Armani;Springfield


I want to delete the String Armani but my command is not working:



cat file.log | grep identifier | cut -d ";" -f | sort | uniq | grep -o '^S*' > newfile.log


I'm following the next post



Is the another way to make it?



PS. There are strings in the same field with different length.










share|improve this question



















  • 1




    Why did you add grep identifier to your pipeline?
    – Jesse_b
    Aug 8 at 21:53






  • 1




    None of the commands in the pipeline seem to align with your stated aim of removing a string after a space - if you want to delete from the space up to the next ; delimiter that can be as simple as sed 's/ [^;]*//' file.log
    – steeldriver
    Aug 8 at 21:56










  • @Jesse_b I invoke the grep "Identifier" because that lines contains the fields that I want to delete.
    – Mareyes
    Aug 8 at 21:59











  • @Mareyes: I don't see the string "identifier" in your sample input at all
    – Jesse_b
    Aug 8 at 22:06










  • @Jesse_b The identifier can be any field in the file. Thre's not be specific one.
    – Mareyes
    Aug 9 at 0:13















up vote
1
down vote

favorite












I have many log files generated like the bellow:



Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George Armani;Springfield


I want to delete the String Armani but my command is not working:



cat file.log | grep identifier | cut -d ";" -f | sort | uniq | grep -o '^S*' > newfile.log


I'm following the next post



Is the another way to make it?



PS. There are strings in the same field with different length.










share|improve this question



















  • 1




    Why did you add grep identifier to your pipeline?
    – Jesse_b
    Aug 8 at 21:53






  • 1




    None of the commands in the pipeline seem to align with your stated aim of removing a string after a space - if you want to delete from the space up to the next ; delimiter that can be as simple as sed 's/ [^;]*//' file.log
    – steeldriver
    Aug 8 at 21:56










  • @Jesse_b I invoke the grep "Identifier" because that lines contains the fields that I want to delete.
    – Mareyes
    Aug 8 at 21:59











  • @Mareyes: I don't see the string "identifier" in your sample input at all
    – Jesse_b
    Aug 8 at 22:06










  • @Jesse_b The identifier can be any field in the file. Thre's not be specific one.
    – Mareyes
    Aug 9 at 0:13













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have many log files generated like the bellow:



Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George Armani;Springfield


I want to delete the String Armani but my command is not working:



cat file.log | grep identifier | cut -d ";" -f | sort | uniq | grep -o '^S*' > newfile.log


I'm following the next post



Is the another way to make it?



PS. There are strings in the same field with different length.










share|improve this question















I have many log files generated like the bellow:



Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George Armani;Springfield


I want to delete the String Armani but my command is not working:



cat file.log | grep identifier | cut -d ";" -f | sort | uniq | grep -o '^S*' > newfile.log


I'm following the next post



Is the another way to make it?



PS. There are strings in the same field with different length.







text-processing awk sed






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 8 at 22:15









Jesse_b

10.5k22659




10.5k22659










asked Aug 8 at 21:51









Mareyes

13611




13611







  • 1




    Why did you add grep identifier to your pipeline?
    – Jesse_b
    Aug 8 at 21:53






  • 1




    None of the commands in the pipeline seem to align with your stated aim of removing a string after a space - if you want to delete from the space up to the next ; delimiter that can be as simple as sed 's/ [^;]*//' file.log
    – steeldriver
    Aug 8 at 21:56










  • @Jesse_b I invoke the grep "Identifier" because that lines contains the fields that I want to delete.
    – Mareyes
    Aug 8 at 21:59











  • @Mareyes: I don't see the string "identifier" in your sample input at all
    – Jesse_b
    Aug 8 at 22:06










  • @Jesse_b The identifier can be any field in the file. Thre's not be specific one.
    – Mareyes
    Aug 9 at 0:13













  • 1




    Why did you add grep identifier to your pipeline?
    – Jesse_b
    Aug 8 at 21:53






  • 1




    None of the commands in the pipeline seem to align with your stated aim of removing a string after a space - if you want to delete from the space up to the next ; delimiter that can be as simple as sed 's/ [^;]*//' file.log
    – steeldriver
    Aug 8 at 21:56










  • @Jesse_b I invoke the grep "Identifier" because that lines contains the fields that I want to delete.
    – Mareyes
    Aug 8 at 21:59











  • @Mareyes: I don't see the string "identifier" in your sample input at all
    – Jesse_b
    Aug 8 at 22:06










  • @Jesse_b The identifier can be any field in the file. Thre's not be specific one.
    – Mareyes
    Aug 9 at 0:13








1




1




Why did you add grep identifier to your pipeline?
– Jesse_b
Aug 8 at 21:53




Why did you add grep identifier to your pipeline?
– Jesse_b
Aug 8 at 21:53




1




1




None of the commands in the pipeline seem to align with your stated aim of removing a string after a space - if you want to delete from the space up to the next ; delimiter that can be as simple as sed 's/ [^;]*//' file.log
– steeldriver
Aug 8 at 21:56




None of the commands in the pipeline seem to align with your stated aim of removing a string after a space - if you want to delete from the space up to the next ; delimiter that can be as simple as sed 's/ [^;]*//' file.log
– steeldriver
Aug 8 at 21:56












@Jesse_b I invoke the grep "Identifier" because that lines contains the fields that I want to delete.
– Mareyes
Aug 8 at 21:59





@Jesse_b I invoke the grep "Identifier" because that lines contains the fields that I want to delete.
– Mareyes
Aug 8 at 21:59













@Mareyes: I don't see the string "identifier" in your sample input at all
– Jesse_b
Aug 8 at 22:06




@Mareyes: I don't see the string "identifier" in your sample input at all
– Jesse_b
Aug 8 at 22:06












@Jesse_b The identifier can be any field in the file. Thre's not be specific one.
– Mareyes
Aug 9 at 0:13





@Jesse_b The identifier can be any field in the file. Thre's not be specific one.
– Mareyes
Aug 9 at 0:13











3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










Using awk:



awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input


This will split the 4th column by whitespace and then set it to the first element.




Should work regardless of what is in the 4th column:



$ cat input
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George Armani;Springfield
02/02/02;777;blabla;Jesse_b;South Park
03/03/03;888;blabla;test name;somewhere

$ awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George;Springfield
02/02/02;777;blabla;Jesse_b;South Park
03/03/03;888;blabla;test;somewhere





share|improve this answer






















  • This is the only answer one I needed, only I have a doubt... "fname" is the field name?? In this case "Node"? Edit: I obtain the same fields.
    – Mareyes
    Aug 9 at 0:34











  • fname is just a variable to hold the split string (In this case I was thinking first name)
    – Jesse_b
    Aug 9 at 0:40










  • Dude, it works. Thank you! I'll study more about awk, is powerfull tool!
    – Mareyes
    Aug 9 at 0:55

















up vote
1
down vote













To delete the text 'Armani' from the file, use this:



$ sed 's/Armani//' myfile
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George ;Springfield
$


To edit it inplace:



$ sed -i 's/Armani//' myfile
$ cat myfile
Date;Time;Brand;User;Node;Location
01/01/01;666;blabla;George ;Springfield
$


If you want to delete all occurrences of 'Armani' within a single line, add a g, e.g. sed 's/Armani//g'






share|improve this answer



























    up vote
    1
    down vote













    The cat is pointless so that can go.
    Identifier is not in your sample input so let's assume you meant blabla.
    Your request to delete the users last name seems completely unrelated to your example command so let's just change that



    grep blabla file.log | perl -pe 's/ [^ ;]+;/;/g' > newfile.log


    If that does not give you what you want you should rewrite your question so that it is clear.






    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%2f461376%2fdelete-string-file-after-space%23new-answer', 'question_page');

      );

      Post as a guest






























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote



      accepted










      Using awk:



      awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input


      This will split the 4th column by whitespace and then set it to the first element.




      Should work regardless of what is in the 4th column:



      $ cat input
      Date;Time;Brand;User;Node;Location
      01/01/01;666;blabla;George Armani;Springfield
      02/02/02;777;blabla;Jesse_b;South Park
      03/03/03;888;blabla;test name;somewhere

      $ awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input
      Date;Time;Brand;User;Node;Location
      01/01/01;666;blabla;George;Springfield
      02/02/02;777;blabla;Jesse_b;South Park
      03/03/03;888;blabla;test;somewhere





      share|improve this answer






















      • This is the only answer one I needed, only I have a doubt... "fname" is the field name?? In this case "Node"? Edit: I obtain the same fields.
        – Mareyes
        Aug 9 at 0:34











      • fname is just a variable to hold the split string (In this case I was thinking first name)
        – Jesse_b
        Aug 9 at 0:40










      • Dude, it works. Thank you! I'll study more about awk, is powerfull tool!
        – Mareyes
        Aug 9 at 0:55














      up vote
      1
      down vote



      accepted










      Using awk:



      awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input


      This will split the 4th column by whitespace and then set it to the first element.




      Should work regardless of what is in the 4th column:



      $ cat input
      Date;Time;Brand;User;Node;Location
      01/01/01;666;blabla;George Armani;Springfield
      02/02/02;777;blabla;Jesse_b;South Park
      03/03/03;888;blabla;test name;somewhere

      $ awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input
      Date;Time;Brand;User;Node;Location
      01/01/01;666;blabla;George;Springfield
      02/02/02;777;blabla;Jesse_b;South Park
      03/03/03;888;blabla;test;somewhere





      share|improve this answer






















      • This is the only answer one I needed, only I have a doubt... "fname" is the field name?? In this case "Node"? Edit: I obtain the same fields.
        – Mareyes
        Aug 9 at 0:34











      • fname is just a variable to hold the split string (In this case I was thinking first name)
        – Jesse_b
        Aug 9 at 0:40










      • Dude, it works. Thank you! I'll study more about awk, is powerfull tool!
        – Mareyes
        Aug 9 at 0:55












      up vote
      1
      down vote



      accepted







      up vote
      1
      down vote



      accepted






      Using awk:



      awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input


      This will split the 4th column by whitespace and then set it to the first element.




      Should work regardless of what is in the 4th column:



      $ cat input
      Date;Time;Brand;User;Node;Location
      01/01/01;666;blabla;George Armani;Springfield
      02/02/02;777;blabla;Jesse_b;South Park
      03/03/03;888;blabla;test name;somewhere

      $ awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input
      Date;Time;Brand;User;Node;Location
      01/01/01;666;blabla;George;Springfield
      02/02/02;777;blabla;Jesse_b;South Park
      03/03/03;888;blabla;test;somewhere





      share|improve this answer














      Using awk:



      awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input


      This will split the 4th column by whitespace and then set it to the first element.




      Should work regardless of what is in the 4th column:



      $ cat input
      Date;Time;Brand;User;Node;Location
      01/01/01;666;blabla;George Armani;Springfield
      02/02/02;777;blabla;Jesse_b;South Park
      03/03/03;888;blabla;test name;somewhere

      $ awk -F; 'OFS = ";" if ($4 ~ " "); split($4, fname, / /); $4=fname[1]; print ' input
      Date;Time;Brand;User;Node;Location
      01/01/01;666;blabla;George;Springfield
      02/02/02;777;blabla;Jesse_b;South Park
      03/03/03;888;blabla;test;somewhere






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Aug 8 at 22:19

























      answered Aug 8 at 22:00









      Jesse_b

      10.5k22659




      10.5k22659











      • This is the only answer one I needed, only I have a doubt... "fname" is the field name?? In this case "Node"? Edit: I obtain the same fields.
        – Mareyes
        Aug 9 at 0:34











      • fname is just a variable to hold the split string (In this case I was thinking first name)
        – Jesse_b
        Aug 9 at 0:40










      • Dude, it works. Thank you! I'll study more about awk, is powerfull tool!
        – Mareyes
        Aug 9 at 0:55
















      • This is the only answer one I needed, only I have a doubt... "fname" is the field name?? In this case "Node"? Edit: I obtain the same fields.
        – Mareyes
        Aug 9 at 0:34











      • fname is just a variable to hold the split string (In this case I was thinking first name)
        – Jesse_b
        Aug 9 at 0:40










      • Dude, it works. Thank you! I'll study more about awk, is powerfull tool!
        – Mareyes
        Aug 9 at 0:55















      This is the only answer one I needed, only I have a doubt... "fname" is the field name?? In this case "Node"? Edit: I obtain the same fields.
      – Mareyes
      Aug 9 at 0:34





      This is the only answer one I needed, only I have a doubt... "fname" is the field name?? In this case "Node"? Edit: I obtain the same fields.
      – Mareyes
      Aug 9 at 0:34













      fname is just a variable to hold the split string (In this case I was thinking first name)
      – Jesse_b
      Aug 9 at 0:40




      fname is just a variable to hold the split string (In this case I was thinking first name)
      – Jesse_b
      Aug 9 at 0:40












      Dude, it works. Thank you! I'll study more about awk, is powerfull tool!
      – Mareyes
      Aug 9 at 0:55




      Dude, it works. Thank you! I'll study more about awk, is powerfull tool!
      – Mareyes
      Aug 9 at 0:55












      up vote
      1
      down vote













      To delete the text 'Armani' from the file, use this:



      $ sed 's/Armani//' myfile
      Date;Time;Brand;User;Node;Location
      01/01/01;666;blabla;George ;Springfield
      $


      To edit it inplace:



      $ sed -i 's/Armani//' myfile
      $ cat myfile
      Date;Time;Brand;User;Node;Location
      01/01/01;666;blabla;George ;Springfield
      $


      If you want to delete all occurrences of 'Armani' within a single line, add a g, e.g. sed 's/Armani//g'






      share|improve this answer
























        up vote
        1
        down vote













        To delete the text 'Armani' from the file, use this:



        $ sed 's/Armani//' myfile
        Date;Time;Brand;User;Node;Location
        01/01/01;666;blabla;George ;Springfield
        $


        To edit it inplace:



        $ sed -i 's/Armani//' myfile
        $ cat myfile
        Date;Time;Brand;User;Node;Location
        01/01/01;666;blabla;George ;Springfield
        $


        If you want to delete all occurrences of 'Armani' within a single line, add a g, e.g. sed 's/Armani//g'






        share|improve this answer






















          up vote
          1
          down vote










          up vote
          1
          down vote









          To delete the text 'Armani' from the file, use this:



          $ sed 's/Armani//' myfile
          Date;Time;Brand;User;Node;Location
          01/01/01;666;blabla;George ;Springfield
          $


          To edit it inplace:



          $ sed -i 's/Armani//' myfile
          $ cat myfile
          Date;Time;Brand;User;Node;Location
          01/01/01;666;blabla;George ;Springfield
          $


          If you want to delete all occurrences of 'Armani' within a single line, add a g, e.g. sed 's/Armani//g'






          share|improve this answer












          To delete the text 'Armani' from the file, use this:



          $ sed 's/Armani//' myfile
          Date;Time;Brand;User;Node;Location
          01/01/01;666;blabla;George ;Springfield
          $


          To edit it inplace:



          $ sed -i 's/Armani//' myfile
          $ cat myfile
          Date;Time;Brand;User;Node;Location
          01/01/01;666;blabla;George ;Springfield
          $


          If you want to delete all occurrences of 'Armani' within a single line, add a g, e.g. sed 's/Armani//g'







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 8 at 21:55









          steve

          12.9k22149




          12.9k22149




















              up vote
              1
              down vote













              The cat is pointless so that can go.
              Identifier is not in your sample input so let's assume you meant blabla.
              Your request to delete the users last name seems completely unrelated to your example command so let's just change that



              grep blabla file.log | perl -pe 's/ [^ ;]+;/;/g' > newfile.log


              If that does not give you what you want you should rewrite your question so that it is clear.






              share|improve this answer


























                up vote
                1
                down vote













                The cat is pointless so that can go.
                Identifier is not in your sample input so let's assume you meant blabla.
                Your request to delete the users last name seems completely unrelated to your example command so let's just change that



                grep blabla file.log | perl -pe 's/ [^ ;]+;/;/g' > newfile.log


                If that does not give you what you want you should rewrite your question so that it is clear.






                share|improve this answer
























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  The cat is pointless so that can go.
                  Identifier is not in your sample input so let's assume you meant blabla.
                  Your request to delete the users last name seems completely unrelated to your example command so let's just change that



                  grep blabla file.log | perl -pe 's/ [^ ;]+;/;/g' > newfile.log


                  If that does not give you what you want you should rewrite your question so that it is clear.






                  share|improve this answer














                  The cat is pointless so that can go.
                  Identifier is not in your sample input so let's assume you meant blabla.
                  Your request to delete the users last name seems completely unrelated to your example command so let's just change that



                  grep blabla file.log | perl -pe 's/ [^ ;]+;/;/g' > newfile.log


                  If that does not give you what you want you should rewrite your question so that it is clear.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Aug 8 at 22:18

























                  answered Aug 8 at 21:58









                  user1133275

                  2,277412




                  2,277412



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461376%2fdelete-string-file-after-space%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      Peggy Mitchell

                      The Forum (Inglewood, California)

                      Palaiologos