I want to delete a column from a row which begins with a particular string in a csv fileHow to manipulate a...

How does the Saturn V Dynamic Test Stand work?

Chess software to analyze games

Does git delete empty folders?

How do slats reduce stall speed?

Total force on upper block in two block system

Are there any OR challenges that are similar to kaggle's competitions?

From France west coast to Portugal via ship?

Cheap storage lockers in Tromsø, Norway

Vacuum collapse -- why do strong metals implode but glass doesn't?

How can I describe being temporarily stupid?

Have only girls been born for a long time in this village?

Can 'in-' mean both 'in' and 'no'?

Interaction between Ethereal Absolution versus Edgar Markov with Captivating Vampire

Why doesn't mathematics collapse down, even though humans quite often make mistakes in their proofs?

"Silverware", "Tableware", and "Dishes"

Nuclear decay triggers

insert several equation in one frame in beamer

Combining extension tube with adapter

Is a butterfly one or two animals?

is it possible to use the organization's name to published a paper in a conference even after I graduate from it

Does C++20 mandate source code being stored in files?

The Lucky House

Are there reliable, formulaic ways to form chords on the guitar?

90s(?) book series about two people transported to a parallel medieval world, she joins city watch, he becomes wizard



I want to delete a column from a row which begins with a particular string in a csv file


How to manipulate a CSV file with sed or awk?Pick columns from a variable length csv fileHow to extract column name (header) from a CSV file which contains the max value in a row?How to sum column values for each row in two csv files using bash script?Remove Columns from a CSV FileRemove an array column from a CSV fileExtract row if both column values appear in a single column from a separate fileGetting a row data from matching column in CSV file in Perl?shell script read from csv column and search filesCopy a row in a CSV file based on a value in another column






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







0















I have a csv file:



test_1,2,data,hi,cat
test_2,3,4,5,6
test_1,3,7,8,9


I want to delete column 3 of the rows which begin with test_1.



I used the cut command to delete column 3 but I do not know how to do it only for a row that begins with test_1.










share|improve this question









New contributor



ShivaniSarin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




























    0















    I have a csv file:



    test_1,2,data,hi,cat
    test_2,3,4,5,6
    test_1,3,7,8,9


    I want to delete column 3 of the rows which begin with test_1.



    I used the cut command to delete column 3 but I do not know how to do it only for a row that begins with test_1.










    share|improve this question









    New contributor



    ShivaniSarin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      0












      0








      0








      I have a csv file:



      test_1,2,data,hi,cat
      test_2,3,4,5,6
      test_1,3,7,8,9


      I want to delete column 3 of the rows which begin with test_1.



      I used the cut command to delete column 3 but I do not know how to do it only for a row that begins with test_1.










      share|improve this question









      New contributor



      ShivaniSarin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I have a csv file:



      test_1,2,data,hi,cat
      test_2,3,4,5,6
      test_1,3,7,8,9


      I want to delete column 3 of the rows which begin with test_1.



      I used the cut command to delete column 3 but I do not know how to do it only for a row that begins with test_1.







      text-processing csv






      share|improve this question









      New contributor



      ShivaniSarin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question









      New contributor



      ShivaniSarin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question








      edited 14 hours ago









      Freddy

      6,4911 gold badge6 silver badges24 bronze badges




      6,4911 gold badge6 silver badges24 bronze badges






      New contributor



      ShivaniSarin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked 2 days ago









      ShivaniSarinShivaniSarin

      6




      6




      New contributor



      ShivaniSarin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      ShivaniSarin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.



























          3 Answers
          3






          active

          oldest

          votes


















          0














          Normally every row of a well formed csv file has the same number of columns, which this would break, but...



          awk 'BEGIN{ FS=OFS="," }
          $1 == "test_1" { print $1,$2,$4,$5; next } 1' yourfile





          share|improve this answer

































            0














            With sed:



            sed '/^test_1/s/,[^,]*//2' file




            • /^test_1/ search for the lines starting with test_1, then


            • s/,[^,]*//2 replace the second occurrence of comma, followed by any non-comma characters with the empty string






            share|improve this answer

































              0














              Done by below command



              awk -F "," '$1 == "test_1" {$3=""}1' filename|sed -r "s/s+/,/g"


              output



              test_1,2,hi,cat
              test_2,3,4,5,6
              test_1,3,8,9





              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
                });


                }
                });






                ShivaniSarin is a new contributor. Be nice, and check out our Code of Conduct.










                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f535941%2fi-want-to-delete-a-column-from-a-row-which-begins-with-a-particular-string-in-a%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









                0














                Normally every row of a well formed csv file has the same number of columns, which this would break, but...



                awk 'BEGIN{ FS=OFS="," }
                $1 == "test_1" { print $1,$2,$4,$5; next } 1' yourfile





                share|improve this answer






























                  0














                  Normally every row of a well formed csv file has the same number of columns, which this would break, but...



                  awk 'BEGIN{ FS=OFS="," }
                  $1 == "test_1" { print $1,$2,$4,$5; next } 1' yourfile





                  share|improve this answer




























                    0












                    0








                    0







                    Normally every row of a well formed csv file has the same number of columns, which this would break, but...



                    awk 'BEGIN{ FS=OFS="," }
                    $1 == "test_1" { print $1,$2,$4,$5; next } 1' yourfile





                    share|improve this answer













                    Normally every row of a well formed csv file has the same number of columns, which this would break, but...



                    awk 'BEGIN{ FS=OFS="," }
                    $1 == "test_1" { print $1,$2,$4,$5; next } 1' yourfile






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 15 hours ago









                    ShawnShawn

                    1362 bronze badges




                    1362 bronze badges




























                        0














                        With sed:



                        sed '/^test_1/s/,[^,]*//2' file




                        • /^test_1/ search for the lines starting with test_1, then


                        • s/,[^,]*//2 replace the second occurrence of comma, followed by any non-comma characters with the empty string






                        share|improve this answer






























                          0














                          With sed:



                          sed '/^test_1/s/,[^,]*//2' file




                          • /^test_1/ search for the lines starting with test_1, then


                          • s/,[^,]*//2 replace the second occurrence of comma, followed by any non-comma characters with the empty string






                          share|improve this answer




























                            0












                            0








                            0







                            With sed:



                            sed '/^test_1/s/,[^,]*//2' file




                            • /^test_1/ search for the lines starting with test_1, then


                            • s/,[^,]*//2 replace the second occurrence of comma, followed by any non-comma characters with the empty string






                            share|improve this answer













                            With sed:



                            sed '/^test_1/s/,[^,]*//2' file




                            • /^test_1/ search for the lines starting with test_1, then


                            • s/,[^,]*//2 replace the second occurrence of comma, followed by any non-comma characters with the empty string







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 14 hours ago









                            FreddyFreddy

                            6,4911 gold badge6 silver badges24 bronze badges




                            6,4911 gold badge6 silver badges24 bronze badges


























                                0














                                Done by below command



                                awk -F "," '$1 == "test_1" {$3=""}1' filename|sed -r "s/s+/,/g"


                                output



                                test_1,2,hi,cat
                                test_2,3,4,5,6
                                test_1,3,8,9





                                share|improve this answer






























                                  0














                                  Done by below command



                                  awk -F "," '$1 == "test_1" {$3=""}1' filename|sed -r "s/s+/,/g"


                                  output



                                  test_1,2,hi,cat
                                  test_2,3,4,5,6
                                  test_1,3,8,9





                                  share|improve this answer




























                                    0












                                    0








                                    0







                                    Done by below command



                                    awk -F "," '$1 == "test_1" {$3=""}1' filename|sed -r "s/s+/,/g"


                                    output



                                    test_1,2,hi,cat
                                    test_2,3,4,5,6
                                    test_1,3,8,9





                                    share|improve this answer













                                    Done by below command



                                    awk -F "," '$1 == "test_1" {$3=""}1' filename|sed -r "s/s+/,/g"


                                    output



                                    test_1,2,hi,cat
                                    test_2,3,4,5,6
                                    test_1,3,8,9






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 7 hours ago









                                    Praveen Kumar BSPraveen Kumar BS

                                    2,3972 gold badges3 silver badges11 bronze badges




                                    2,3972 gold badges3 silver badges11 bronze badges

























                                        ShivaniSarin is a new contributor. Be nice, and check out our Code of Conduct.










                                        draft saved

                                        draft discarded


















                                        ShivaniSarin is a new contributor. Be nice, and check out our Code of Conduct.













                                        ShivaniSarin is a new contributor. Be nice, and check out our Code of Conduct.












                                        ShivaniSarin is a new contributor. Be nice, and check out our Code of Conduct.
















                                        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%2f535941%2fi-want-to-delete-a-column-from-a-row-which-begins-with-a-particular-string-in-a%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

                                        Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

                                        The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

                                        Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...