How can I remove rest of file from string for all files?Remove all text before last space in text file from CLIHow to remove domain part of each line from text file containing email addressesFilter consecutive identical characters using Sed and GrepHow to find logs that contain certain string in lots of gz/regular files and save it as one/more txt files?command to remove specific string from multiple filesRemove all non-numeric characters from text filesDelete all lines from middle of a line matching a string until the second string match is foundHow sed can be used to replace multiple patterns within a string for different patternsBash, get values from json file, all in one line

Rat proofing compost bin but allowing worms in

How to read a file line by line in Julia?

How to make a gift without seeming creepy?

universal string conversion

Had there been instances of national states banning harmful imports before the Opium wars?

What does a "le" mean between subject and verb?

How come the Russian cognate for the Czech word "čerstvý" (fresh) means entirely the opposite thing (stale)?

How stable are PID loops really?

Would we have more than 8 minutes of light, if the sun "went out"?

Does permanent loss of castling rights reset three fold repetition

Why can I ping 10.0.0.0/8 addresses from a 192.168.1.0/24 subnet?

How much money should I save in order to generate $1000/month for the rest of my life?

Over powered shield?

In 1700s, why was 'books that never read' grammatical?

one-liner vs script

Why would they pick a gamma distribution here?

Why did a young George Washington sign a document admitting to assassinating a French military officer?

Is having your hand in your pocket during a presentation bad?

Are great composers almost always prodigious performers?

Can something have more sugar per 100g than the percentage of sugar that's in it?

How are steel imports supposed to threaten US national security?

What is /dev/null and why can't I use hx on it?

Why do English transliterations of Arabic names have so many Qs in them?

Is insurance company’s preferred auto shop biased?



How can I remove rest of file from string for all files?


Remove all text before last space in text file from CLIHow to remove domain part of each line from text file containing email addressesFilter consecutive identical characters using Sed and GrepHow to find logs that contain certain string in lots of gz/regular files and save it as one/more txt files?command to remove specific string from multiple filesRemove all non-numeric characters from text filesDelete all lines from middle of a line matching a string until the second string match is foundHow sed can be used to replace multiple patterns within a string for different patternsBash, get values from json file, all in one line






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









4















How can I remove rest of file from string for all files?



For example, input files 1 and 2, string is ddd.



Input file 1.



aaa
bbb
ccc
ddfbbd dddaaa
eee


Input file 2.



ccc
aergddd
dasdvsdb


Output file 1.



aaa
bbb
ccc
ddfbbd


Output file 2.



ccc
aerg









share|improve this question
































    4















    How can I remove rest of file from string for all files?



    For example, input files 1 and 2, string is ddd.



    Input file 1.



    aaa
    bbb
    ccc
    ddfbbd dddaaa
    eee


    Input file 2.



    ccc
    aergddd
    dasdvsdb


    Output file 1.



    aaa
    bbb
    ccc
    ddfbbd


    Output file 2.



    ccc
    aerg









    share|improve this question




























      4












      4








      4


      1






      How can I remove rest of file from string for all files?



      For example, input files 1 and 2, string is ddd.



      Input file 1.



      aaa
      bbb
      ccc
      ddfbbd dddaaa
      eee


      Input file 2.



      ccc
      aergddd
      dasdvsdb


      Output file 1.



      aaa
      bbb
      ccc
      ddfbbd


      Output file 2.



      ccc
      aerg









      share|improve this question
















      How can I remove rest of file from string for all files?



      For example, input files 1 and 2, string is ddd.



      Input file 1.



      aaa
      bbb
      ccc
      ddfbbd dddaaa
      eee


      Input file 2.



      ccc
      aergddd
      dasdvsdb


      Output file 1.



      aaa
      bbb
      ccc
      ddfbbd


      Output file 2.



      ccc
      aerg






      text-processing sed






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 7 hours ago









      αғsнιη

      25.9k23 gold badges105 silver badges167 bronze badges




      25.9k23 gold badges105 silver badges167 bronze badges










      asked 8 hours ago









      genderbeegenderbee

      1407 bronze badges




      1407 bronze badges























          3 Answers
          3






          active

          oldest

          votes


















          6
















          With GNU sed:



          str="ddd"
          for file in 1 2; do
          sed -i "/$str/ s/$str.*//; q" "$file"
          done


          This needs to be in a loop: otherwise the q command would abort the whole process after processing only the first file.






          share|improve this answer


































            2
















            with GNU awk, we can do:



            awk 'function output() print >>FILENAME".out" 
            /ddd/ sub(/ddd.*/,""); output(); nextfile
            output() ' file[12]





            share|improve this answer
































              2
















              With Perl:



              perl -i -0777 -pe 's/ddd[sS]*//' file


              • -i: modify the file in-place.


              • -0777: force Perl to slurp the file as whole, not line by line.



              • -pe:




                • -p: loop Perl code.


                • -e: execute Perl code.


              • 's/ddd[sS]*//': replace everything (every whitespace (s) and non-whitespace (S) character) after ddd (including it) with an empty string.


              More about Perl flags can be found here.






              share|improve this answer



























              • Why not just s/ddd.*//?

                – dessert
                6 hours ago











              • @dessert .* stops matching at newline.

                – user3140225
                5 hours ago












              • Ah, so a true equivalent would be [Nn]* – nice, thanks!

                – dessert
                4 hours ago












              • You can use..* if you add the m or s flag to the s/// command (I forget which one)

                – glenn jackman
                1 hour ago












              Your Answer








              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "89"
              ;
              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/4.0/"u003ecc by-sa 4.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%2faskubuntu.com%2fquestions%2f1177693%2fhow-can-i-remove-rest-of-file-from-string-for-all-files%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









              6
















              With GNU sed:



              str="ddd"
              for file in 1 2; do
              sed -i "/$str/ s/$str.*//; q" "$file"
              done


              This needs to be in a loop: otherwise the q command would abort the whole process after processing only the first file.






              share|improve this answer































                6
















                With GNU sed:



                str="ddd"
                for file in 1 2; do
                sed -i "/$str/ s/$str.*//; q" "$file"
                done


                This needs to be in a loop: otherwise the q command would abort the whole process after processing only the first file.






                share|improve this answer





























                  6














                  6










                  6









                  With GNU sed:



                  str="ddd"
                  for file in 1 2; do
                  sed -i "/$str/ s/$str.*//; q" "$file"
                  done


                  This needs to be in a loop: otherwise the q command would abort the whole process after processing only the first file.






                  share|improve this answer















                  With GNU sed:



                  str="ddd"
                  for file in 1 2; do
                  sed -i "/$str/ s/$str.*//; q" "$file"
                  done


                  This needs to be in a loop: otherwise the q command would abort the whole process after processing only the first file.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 7 hours ago









                  dessert

                  29.2k7 gold badges87 silver badges121 bronze badges




                  29.2k7 gold badges87 silver badges121 bronze badges










                  answered 7 hours ago









                  glenn jackmanglenn jackman

                  13.3k26 silver badges46 bronze badges




                  13.3k26 silver badges46 bronze badges


























                      2
















                      with GNU awk, we can do:



                      awk 'function output() print >>FILENAME".out" 
                      /ddd/ sub(/ddd.*/,""); output(); nextfile
                      output() ' file[12]





                      share|improve this answer





























                        2
















                        with GNU awk, we can do:



                        awk 'function output() print >>FILENAME".out" 
                        /ddd/ sub(/ddd.*/,""); output(); nextfile
                        output() ' file[12]





                        share|improve this answer



























                          2














                          2










                          2









                          with GNU awk, we can do:



                          awk 'function output() print >>FILENAME".out" 
                          /ddd/ sub(/ddd.*/,""); output(); nextfile
                          output() ' file[12]





                          share|improve this answer













                          with GNU awk, we can do:



                          awk 'function output() print >>FILENAME".out" 
                          /ddd/ sub(/ddd.*/,""); output(); nextfile
                          output() ' file[12]






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 7 hours ago









                          αғsнιηαғsнιη

                          25.9k23 gold badges105 silver badges167 bronze badges




                          25.9k23 gold badges105 silver badges167 bronze badges
























                              2
















                              With Perl:



                              perl -i -0777 -pe 's/ddd[sS]*//' file


                              • -i: modify the file in-place.


                              • -0777: force Perl to slurp the file as whole, not line by line.



                              • -pe:




                                • -p: loop Perl code.


                                • -e: execute Perl code.


                              • 's/ddd[sS]*//': replace everything (every whitespace (s) and non-whitespace (S) character) after ddd (including it) with an empty string.


                              More about Perl flags can be found here.






                              share|improve this answer



























                              • Why not just s/ddd.*//?

                                – dessert
                                6 hours ago











                              • @dessert .* stops matching at newline.

                                – user3140225
                                5 hours ago












                              • Ah, so a true equivalent would be [Nn]* – nice, thanks!

                                – dessert
                                4 hours ago












                              • You can use..* if you add the m or s flag to the s/// command (I forget which one)

                                – glenn jackman
                                1 hour ago















                              2
















                              With Perl:



                              perl -i -0777 -pe 's/ddd[sS]*//' file


                              • -i: modify the file in-place.


                              • -0777: force Perl to slurp the file as whole, not line by line.



                              • -pe:




                                • -p: loop Perl code.


                                • -e: execute Perl code.


                              • 's/ddd[sS]*//': replace everything (every whitespace (s) and non-whitespace (S) character) after ddd (including it) with an empty string.


                              More about Perl flags can be found here.






                              share|improve this answer



























                              • Why not just s/ddd.*//?

                                – dessert
                                6 hours ago











                              • @dessert .* stops matching at newline.

                                – user3140225
                                5 hours ago












                              • Ah, so a true equivalent would be [Nn]* – nice, thanks!

                                – dessert
                                4 hours ago












                              • You can use..* if you add the m or s flag to the s/// command (I forget which one)

                                – glenn jackman
                                1 hour ago













                              2














                              2










                              2









                              With Perl:



                              perl -i -0777 -pe 's/ddd[sS]*//' file


                              • -i: modify the file in-place.


                              • -0777: force Perl to slurp the file as whole, not line by line.



                              • -pe:




                                • -p: loop Perl code.


                                • -e: execute Perl code.


                              • 's/ddd[sS]*//': replace everything (every whitespace (s) and non-whitespace (S) character) after ddd (including it) with an empty string.


                              More about Perl flags can be found here.






                              share|improve this answer















                              With Perl:



                              perl -i -0777 -pe 's/ddd[sS]*//' file


                              • -i: modify the file in-place.


                              • -0777: force Perl to slurp the file as whole, not line by line.



                              • -pe:




                                • -p: loop Perl code.


                                • -e: execute Perl code.


                              • 's/ddd[sS]*//': replace everything (every whitespace (s) and non-whitespace (S) character) after ddd (including it) with an empty string.


                              More about Perl flags can be found here.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited 6 hours ago









                              dessert

                              29.2k7 gold badges87 silver badges121 bronze badges




                              29.2k7 gold badges87 silver badges121 bronze badges










                              answered 6 hours ago









                              user3140225user3140225

                              2,1668 silver badges22 bronze badges




                              2,1668 silver badges22 bronze badges















                              • Why not just s/ddd.*//?

                                – dessert
                                6 hours ago











                              • @dessert .* stops matching at newline.

                                – user3140225
                                5 hours ago












                              • Ah, so a true equivalent would be [Nn]* – nice, thanks!

                                – dessert
                                4 hours ago












                              • You can use..* if you add the m or s flag to the s/// command (I forget which one)

                                – glenn jackman
                                1 hour ago

















                              • Why not just s/ddd.*//?

                                – dessert
                                6 hours ago











                              • @dessert .* stops matching at newline.

                                – user3140225
                                5 hours ago












                              • Ah, so a true equivalent would be [Nn]* – nice, thanks!

                                – dessert
                                4 hours ago












                              • You can use..* if you add the m or s flag to the s/// command (I forget which one)

                                – glenn jackman
                                1 hour ago
















                              Why not just s/ddd.*//?

                              – dessert
                              6 hours ago





                              Why not just s/ddd.*//?

                              – dessert
                              6 hours ago













                              @dessert .* stops matching at newline.

                              – user3140225
                              5 hours ago






                              @dessert .* stops matching at newline.

                              – user3140225
                              5 hours ago














                              Ah, so a true equivalent would be [Nn]* – nice, thanks!

                              – dessert
                              4 hours ago






                              Ah, so a true equivalent would be [Nn]* – nice, thanks!

                              – dessert
                              4 hours ago














                              You can use..* if you add the m or s flag to the s/// command (I forget which one)

                              – glenn jackman
                              1 hour ago





                              You can use..* if you add the m or s flag to the s/// command (I forget which one)

                              – glenn jackman
                              1 hour ago


















                              draft saved

                              draft discarded















































                              Thanks for contributing an answer to Ask Ubuntu!


                              • 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%2faskubuntu.com%2fquestions%2f1177693%2fhow-can-i-remove-rest-of-file-from-string-for-all-files%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

                              Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                              Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                              François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480