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

Where else does the Shulchan Aruch quote an authority by name?

New order #4: World

extract characters between two commas?

Is ipsum/ipsa/ipse a third person pronoun, or can it serve other functions?

What does 'script /dev/null' do?

Shall I use personal or official e-mail account when registering to external websites for work purpose?

What does "enim et" mean?

Why is the design of haulage companies so “special”?

Extreme, but not acceptable situation and I can't start the work tomorrow morning

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

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

Is there a way to make member function NOT callable from constructor?

What do the Banks children have against barley water?

Domain expired, GoDaddy holds it and is asking more money

How can I add custom success page

Finding files for which a command fails

Is Social Media Science Fiction?

Need help identifying/translating a plaque in Tangier, Morocco

Re-submission of rejected manuscript without informing co-authors

What does it exactly mean if a random variable follows a distribution

What do you call something that goes against the spirit of the law, but is legal when interpreting the law to the letter?

Calculate Levenshtein distance between two strings in Python

Can I find out the caloric content of bread by dehydrating it?

Manga about a female worker who got dragged into another world together with this high school girl and she was just told she's not needed anymore



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;








3















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




























    3















    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
























      3












      3








      3








      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 7 hours ago









      Anna1364Anna1364

      449213




      449213




















          3 Answers
          3






          active

          oldest

          votes


















          13














          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
            7 hours ago


















          2














          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
            5 hours ago











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

            – Kusalananda
            5 hours ago


















          1














          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









            13














            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
              7 hours ago















            13














            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
              7 hours ago













            13












            13








            13







            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 7 hours ago









            iruvariruvar

            12.4k63063




            12.4k63063







            • 1





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

              – Kusalananda
              7 hours ago












            • 1





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

              – Kusalananda
              7 hours ago







            1




            1





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

            – Kusalananda
            7 hours ago





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

            – Kusalananda
            7 hours ago













            2














            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
              5 hours ago











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

              – Kusalananda
              5 hours ago















            2














            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
              5 hours ago











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

              – Kusalananda
              5 hours ago













            2












            2








            2







            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 7 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
              5 hours ago











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

              – Kusalananda
              5 hours 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
              5 hours ago











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

              – Kusalananda
              5 hours 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
            5 hours 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
            5 hours ago













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

            – Kusalananda
            5 hours ago





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

            – Kusalananda
            5 hours ago











            1














            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



























              1














              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

























                1












                1








                1







                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 7 hours ago









                unxnutunxnut

                3,80721120




                3,80721120



























                    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

                    Oświęcim Innehåll Historia | Källor | Externa länkar | Navigeringsmeny50°2′18″N 19°13′17″Ö / 50.03833°N 19.22139°Ö / 50.03833; 19.2213950°2′18″N 19°13′17″Ö / 50.03833°N 19.22139°Ö / 50.03833; 19.221393089658Nordisk familjebok, AuschwitzInsidan tro och existensJewish Community i OświęcimAuschwitz Jewish Center: MuseumAuschwitz Jewish Center

                    Valle di Casies Indice Geografia fisica | Origini del nome | Storia | Società | Amministrazione | Sport | Note | Bibliografia | Voci correlate | Altri progetti | Collegamenti esterni | Menu di navigazione46°46′N 12°11′E / 46.766667°N 12.183333°E46.766667; 12.183333 (Valle di Casies)46°46′N 12°11′E / 46.766667°N 12.183333°E46.766667; 12.183333 (Valle di Casies)Sito istituzionaleAstat Censimento della popolazione 2011 - Determinazione della consistenza dei tre gruppi linguistici della Provincia Autonoma di Bolzano-Alto Adige - giugno 2012Numeri e fattiValle di CasiesDato IstatTabella dei gradi/giorno dei Comuni italiani raggruppati per Regione e Provincia26 agosto 1993, n. 412Heraldry of the World: GsiesStatistiche I.StatValCasies.comWikimedia CommonsWikimedia CommonsValle di CasiesSito ufficialeValle di CasiesMM14870458910042978-6

                    Typsetting diagram chases (with TikZ?) Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)How to define the default vertical distance between nodes?Draw edge on arcNumerical conditional within tikz keys?TikZ: Drawing an arc from an intersection to an intersectionDrawing rectilinear curves in Tikz, aka an Etch-a-Sketch drawingLine up nested tikz enviroments or how to get rid of themHow to place nodes in an absolute coordinate system in tikzCommutative diagram with curve connecting between nodesTikz with standalone: pinning tikz coordinates to page cmDrawing a Decision Diagram with Tikz and layout manager