extract characters between two commas?Text processing - join every two lines with commasRemove entire row in a file if first column is repeatedMerging two files, one column at a timeJoin two textfiles on 1st column keeping order and unpairable lines from 1st fileHow to print lines if two fields have identical values?Delete lines that matches a string before commahow to remove comma and strings after a comma in a file?Fastest way to sum Nth column in text fileHow to extract the first row for each entry in the first column?Compare two files and get unmatched rows from the second file based on first and second column

Is Social Media Science Fiction?

Pristine Bit Checking

Finding files for which a command fails

Is repealing the EU Withdrawal Act a precondition of revoking Article 50?

How to make payment on the internet without leaving a money trail?

I see my dog run

Lied on resume at previous job

What is GPS' 19 year rollover and does it present a cybersecurity issue?

Crop image to path created in TikZ?

Latin words with no plurals in English

Why do we use polarized capacitors?

Symmetry in quantum mechanics

Ideas for colorfully and clearly highlighting graph edges according to weights

LM317 - Calculate dissipation due to voltage drop

Can I legally use front facing blue light in the UK?

How do you conduct xenoanthropology after first contact?

What is the meaning of "of trouble" in the following sentence?

Imbalanced dataset binary classification

Does a dangling wire really electrocute me if I'm standing in water?

Why was the "bread communication" in the arena of Catching Fire left out in the movie?

Is domain driven design an anti-SQL pattern?

Email Account under attack (really) - anything I can do?

New order #4: World

Check if two datetimes are between two others



extract characters between two commas?


Text processing - join every two lines with commasRemove entire row in a file if first column is repeatedMerging two files, one column at a timeJoin two textfiles on 1st column keeping order and unpairable lines from 1st fileHow to print lines if two fields have identical values?Delete lines that matches a string before commahow to remove comma and strings after a comma in a file?Fastest way to sum Nth column in text fileHow to extract the first row for each entry in the first column?Compare two files and get unmatched rows from the second file based on first and second column






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








1















I have a file with ~ 3 million rows, here is the first few lines of my file:



head out.txt
NA
NA
NA
NA
NA
gene85752,gene85753
gene85752,gene85753
gene85752,gene85753
gene85752,gene85753
gene85752,gene85753
gene85752,gene85753
gene85752,gene85753,gene85754
gene85752,gene85753,gene85754
gene85752,gene85753,gene85754
gene85752,gene85753,gene85754
gene85752,gene85753
gene85752,gene85753
gene85752,gene85753
gene85752,gene85753
gene85752,gene85753
gene85752,gene85753
gene85752,gene85753
gene85752,gene85753
gene85752,gene85753
gene85752
gene85752


For those rows that are separated by ",", I want to keep everything after the first comma and before the second comma.
This is my desired output:



outgood.txt
NA
NA
NA
NA
NA
gene85753
gene85753
gene85753
gene85753
gene85753
gene85753
gene85753
gene85753
gene85753
gene85753
gene85753
gene85753
gene85753
gene85753
gene85753
gene85753
gene85753
gene85753
gene85753
gene85752
gene85752









share|improve this question




























    1















    I have a file with ~ 3 million rows, here is the first few lines of my file:



    head out.txt
    NA
    NA
    NA
    NA
    NA
    gene85752,gene85753
    gene85752,gene85753
    gene85752,gene85753
    gene85752,gene85753
    gene85752,gene85753
    gene85752,gene85753
    gene85752,gene85753,gene85754
    gene85752,gene85753,gene85754
    gene85752,gene85753,gene85754
    gene85752,gene85753,gene85754
    gene85752,gene85753
    gene85752,gene85753
    gene85752,gene85753
    gene85752,gene85753
    gene85752,gene85753
    gene85752,gene85753
    gene85752,gene85753
    gene85752,gene85753
    gene85752,gene85753
    gene85752
    gene85752


    For those rows that are separated by ",", I want to keep everything after the first comma and before the second comma.
    This is my desired output:



    outgood.txt
    NA
    NA
    NA
    NA
    NA
    gene85753
    gene85753
    gene85753
    gene85753
    gene85753
    gene85753
    gene85753
    gene85753
    gene85753
    gene85753
    gene85753
    gene85753
    gene85753
    gene85753
    gene85753
    gene85753
    gene85753
    gene85753
    gene85753
    gene85752
    gene85752









    share|improve this question
























      1












      1








      1








      I have a file with ~ 3 million rows, here is the first few lines of my file:



      head out.txt
      NA
      NA
      NA
      NA
      NA
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753,gene85754
      gene85752,gene85753,gene85754
      gene85752,gene85753,gene85754
      gene85752,gene85753,gene85754
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752
      gene85752


      For those rows that are separated by ",", I want to keep everything after the first comma and before the second comma.
      This is my desired output:



      outgood.txt
      NA
      NA
      NA
      NA
      NA
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85752
      gene85752









      share|improve this question














      I have a file with ~ 3 million rows, here is the first few lines of my file:



      head out.txt
      NA
      NA
      NA
      NA
      NA
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753,gene85754
      gene85752,gene85753,gene85754
      gene85752,gene85753,gene85754
      gene85752,gene85753,gene85754
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752,gene85753
      gene85752
      gene85752


      For those rows that are separated by ",", I want to keep everything after the first comma and before the second comma.
      This is my desired output:



      outgood.txt
      NA
      NA
      NA
      NA
      NA
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85753
      gene85752
      gene85752






      text-processing awk






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 hours ago









      Anna1364Anna1364

      439213




      439213




















          3 Answers
          3






          active

          oldest

          votes


















          6














          Since cut prints non-delimited lines by default the following works



          cut -f2 -d, file





          share|improve this answer


















          • 1





            It's nice when someone remember the little quirks of standard tools.

            – Kusalananda
            1 hour ago


















          1














          awk -F, 'NF > 1 $1 = $2 print $1 ' file


          This uses awk to parse the file as lines consisting of comma-delimited fields.



          The code detects when there is more than a single field on a line, and when there is, the first field is replaced by the second field. The first field, either unmodified or modified by the conditional code, is then printed.






          share|improve this answer























          • With a big file, this would probably be faster: awk -F, 'print(NF>1 ? $2 : $1)' -- since you won't have to rewrite $0

            – glenn jackman
            18 mins ago











          • @glennjackman Well, the cut solution would be even faster in any case.

            – Kusalananda
            15 mins ago


















          0














          awk -F, 'NF == 1 print $1
          NF > 1 print $2' filename


          This will print just the first string if there is no comma, second string if there is one or more comma.






          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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2funix.stackexchange.com%2fquestions%2f511284%2fextract-characters-between-two-commas%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














            Since cut prints non-delimited lines by default the following works



            cut -f2 -d, file





            share|improve this answer


















            • 1





              It's nice when someone remember the little quirks of standard tools.

              – Kusalananda
              1 hour ago















            6














            Since cut prints non-delimited lines by default the following works



            cut -f2 -d, file





            share|improve this answer


















            • 1





              It's nice when someone remember the little quirks of standard tools.

              – Kusalananda
              1 hour ago













            6












            6








            6







            Since cut prints non-delimited lines by default the following works



            cut -f2 -d, file





            share|improve this answer













            Since cut prints non-delimited lines by default the following works



            cut -f2 -d, file






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 hours ago









            iruvariruvar

            12.3k63062




            12.3k63062







            • 1





              It's nice when someone remember the little quirks of standard tools.

              – Kusalananda
              1 hour ago












            • 1





              It's nice when someone remember the little quirks of standard tools.

              – Kusalananda
              1 hour ago







            1




            1





            It's nice when someone remember the little quirks of standard tools.

            – Kusalananda
            1 hour ago





            It's nice when someone remember the little quirks of standard tools.

            – Kusalananda
            1 hour ago













            1














            awk -F, 'NF > 1 $1 = $2 print $1 ' file


            This uses awk to parse the file as lines consisting of comma-delimited fields.



            The code detects when there is more than a single field on a line, and when there is, the first field is replaced by the second field. The first field, either unmodified or modified by the conditional code, is then printed.






            share|improve this answer























            • With a big file, this would probably be faster: awk -F, 'print(NF>1 ? $2 : $1)' -- since you won't have to rewrite $0

              – glenn jackman
              18 mins ago











            • @glennjackman Well, the cut solution would be even faster in any case.

              – Kusalananda
              15 mins ago















            1














            awk -F, 'NF > 1 $1 = $2 print $1 ' file


            This uses awk to parse the file as lines consisting of comma-delimited fields.



            The code detects when there is more than a single field on a line, and when there is, the first field is replaced by the second field. The first field, either unmodified or modified by the conditional code, is then printed.






            share|improve this answer























            • With a big file, this would probably be faster: awk -F, 'print(NF>1 ? $2 : $1)' -- since you won't have to rewrite $0

              – glenn jackman
              18 mins ago











            • @glennjackman Well, the cut solution would be even faster in any case.

              – Kusalananda
              15 mins ago













            1












            1








            1







            awk -F, 'NF > 1 $1 = $2 print $1 ' file


            This uses awk to parse the file as lines consisting of comma-delimited fields.



            The code detects when there is more than a single field on a line, and when there is, the first field is replaced by the second field. The first field, either unmodified or modified by the conditional code, is then printed.






            share|improve this answer













            awk -F, 'NF > 1 $1 = $2 print $1 ' file


            This uses awk to parse the file as lines consisting of comma-delimited fields.



            The code detects when there is more than a single field on a line, and when there is, the first field is replaced by the second field. The first field, either unmodified or modified by the conditional code, is then printed.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 hours ago









            KusalanandaKusalananda

            140k17261435




            140k17261435












            • With a big file, this would probably be faster: awk -F, 'print(NF>1 ? $2 : $1)' -- since you won't have to rewrite $0

              – glenn jackman
              18 mins ago











            • @glennjackman Well, the cut solution would be even faster in any case.

              – Kusalananda
              15 mins ago

















            • With a big file, this would probably be faster: awk -F, 'print(NF>1 ? $2 : $1)' -- since you won't have to rewrite $0

              – glenn jackman
              18 mins ago











            • @glennjackman Well, the cut solution would be even faster in any case.

              – Kusalananda
              15 mins ago
















            With a big file, this would probably be faster: awk -F, 'print(NF>1 ? $2 : $1)' -- since you won't have to rewrite $0

            – glenn jackman
            18 mins ago





            With a big file, this would probably be faster: awk -F, 'print(NF>1 ? $2 : $1)' -- since you won't have to rewrite $0

            – glenn jackman
            18 mins ago













            @glennjackman Well, the cut solution would be even faster in any case.

            – Kusalananda
            15 mins ago





            @glennjackman Well, the cut solution would be even faster in any case.

            – Kusalananda
            15 mins ago











            0














            awk -F, 'NF == 1 print $1
            NF > 1 print $2' filename


            This will print just the first string if there is no comma, second string if there is one or more comma.






            share|improve this answer



























              0














              awk -F, 'NF == 1 print $1
              NF > 1 print $2' filename


              This will print just the first string if there is no comma, second string if there is one or more comma.






              share|improve this answer

























                0












                0








                0







                awk -F, 'NF == 1 print $1
                NF > 1 print $2' filename


                This will print just the first string if there is no comma, second string if there is one or more comma.






                share|improve this answer













                awk -F, 'NF == 1 print $1
                NF > 1 print $2' filename


                This will print just the first string if there is no comma, second string if there is one or more comma.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 hours ago









                unxnutunxnut

                3,79721120




                3,79721120



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • 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%2funix.stackexchange.com%2fquestions%2f511284%2fextract-characters-between-two-commas%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

                    Are there any AGPL-style licences that require source code modifications to be public? Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Force derivative works to be publicAre there any GPL like licenses for Apple App Store?Do you violate the GPL if you provide source code that cannot be compiled?GPL - is it distribution to use libraries in an appliance loaned to customers?Distributing App for free which uses GPL'ed codeModifications of server software under GPL, with web/CLI interfaceDoes using an AGPLv3-licensed library prevent me from dual-licensing my own source code?Can I publish only select code under GPLv3 from a private project?Is there published precedent regarding the scope of covered work that uses AGPL software?If MIT licensed code links to GPL licensed code what should be the license of the resulting binary program?If I use a public API endpoint that has its source code licensed under AGPL in my app, do I need to disclose my source?

                    2013 GY136 Descoberta | Órbita | Referências Menu de navegação«List Of Centaurs and Scattered-Disk Objects»«List of Known Trans-Neptunian Objects»

                    Metrô de Los Teques Índice Linhas | Estações | Ver também | Referências Ligações externas | Menu de navegação«INSTITUCIÓN»«Mapa de rutas»originalMetrô de Los TequesC.A. Metro Los Teques |Alcaldía de Guaicaipuro – Sitio OficialGobernacion de Mirandaeeeeeee