remove n columns from CSV file [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have a csv file with data as below :



12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ


I need to remove all date columns from the file through Unix.










share|improve this question















closed as unclear what you're asking by jasonwryan, Jeff Schaller, thrig, maulinglawns, αғsнιη Sep 6 at 2:19


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 5




    What have you tried?
    – jasonwryan
    Sep 5 at 17:50






  • 2




    Are the positions of the date columns always the same?
    – KM.
    Sep 5 at 17:54










  • Yes position is always same for date column
    – UnixLearner
    Sep 6 at 9:00














up vote
0
down vote

favorite












I have a csv file with data as below :



12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ


I need to remove all date columns from the file through Unix.










share|improve this question















closed as unclear what you're asking by jasonwryan, Jeff Schaller, thrig, maulinglawns, αғsнιη Sep 6 at 2:19


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 5




    What have you tried?
    – jasonwryan
    Sep 5 at 17:50






  • 2




    Are the positions of the date columns always the same?
    – KM.
    Sep 5 at 17:54










  • Yes position is always same for date column
    – UnixLearner
    Sep 6 at 9:00












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a csv file with data as below :



12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ


I need to remove all date columns from the file through Unix.










share|improve this question















I have a csv file with data as below :



12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ


I need to remove all date columns from the file through Unix.







linux shell-script csv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 5 at 18:16









Jeff Schaller

33k849111




33k849111










asked Sep 5 at 17:49









UnixLearner

121




121




closed as unclear what you're asking by jasonwryan, Jeff Schaller, thrig, maulinglawns, αғsнιη Sep 6 at 2:19


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by jasonwryan, Jeff Schaller, thrig, maulinglawns, αғsнιη Sep 6 at 2:19


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









  • 5




    What have you tried?
    – jasonwryan
    Sep 5 at 17:50






  • 2




    Are the positions of the date columns always the same?
    – KM.
    Sep 5 at 17:54










  • Yes position is always same for date column
    – UnixLearner
    Sep 6 at 9:00












  • 5




    What have you tried?
    – jasonwryan
    Sep 5 at 17:50






  • 2




    Are the positions of the date columns always the same?
    – KM.
    Sep 5 at 17:54










  • Yes position is always same for date column
    – UnixLearner
    Sep 6 at 9:00







5




5




What have you tried?
– jasonwryan
Sep 5 at 17:50




What have you tried?
– jasonwryan
Sep 5 at 17:50




2




2




Are the positions of the date columns always the same?
– KM.
Sep 5 at 17:54




Are the positions of the date columns always the same?
– KM.
Sep 5 at 17:54












Yes position is always same for date column
– UnixLearner
Sep 6 at 9:00




Yes position is always same for date column
– UnixLearner
Sep 6 at 9:00










3 Answers
3






active

oldest

votes

















up vote
2
down vote













Using awk:



echo "12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ" | awk -F ',' 'for (i=1;i<=NF;i++) if($i !~ "-") printf "%s,",$i' 

12,1234,ABC60,3456,AB60,7580,PQ,


  • prints the columns which are not having -





share|improve this answer




















  • Thank you so much. It worked for me
    – UnixLearner
    Sep 12 at 6:34

















up vote
2
down vote













Assuming there are no embedded commas inside a comma-delimited field, and that you want to remove columns 3, 6 and 9.



$ cut -d, -f1,2,4,5,7,8,10 <file
12,1234,ABC60,3456,AB60,7580,PQ


The cut command extracts the given columns out of a file. By default, tabs are used as column delimiters, but with -d, we set the delimiter to a comma. The -f option takes the column numbers (or ranges of column numbers) that are to be extracted.



Using csvcut from CSVkit, which is a real CSV parser, we can also handle fields which contains embedded commas:



$ csvcut -c 1,2,4,5,7,8,10 file
12,1234,ABC60,3456,AB60,7580,PQ


This tool also handles cutting on column names if the file has headers for each column.






share|improve this answer





























    up vote
    1
    down vote













    Albeit not awk, but...



    tr ',' 'n' < csv | grep -E -v '^[0-9]2-[0-9]2-[0-9]4' | tr 'n' ','
    12,1234,ABC60,3456,AB60,7580,PQ,





    share|improve this answer



























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      2
      down vote













      Using awk:



      echo "12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ" | awk -F ',' 'for (i=1;i<=NF;i++) if($i !~ "-") printf "%s,",$i' 

      12,1234,ABC60,3456,AB60,7580,PQ,


      • prints the columns which are not having -





      share|improve this answer




















      • Thank you so much. It worked for me
        – UnixLearner
        Sep 12 at 6:34














      up vote
      2
      down vote













      Using awk:



      echo "12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ" | awk -F ',' 'for (i=1;i<=NF;i++) if($i !~ "-") printf "%s,",$i' 

      12,1234,ABC60,3456,AB60,7580,PQ,


      • prints the columns which are not having -





      share|improve this answer




















      • Thank you so much. It worked for me
        – UnixLearner
        Sep 12 at 6:34












      up vote
      2
      down vote










      up vote
      2
      down vote









      Using awk:



      echo "12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ" | awk -F ',' 'for (i=1;i<=NF;i++) if($i !~ "-") printf "%s,",$i' 

      12,1234,ABC60,3456,AB60,7580,PQ,


      • prints the columns which are not having -





      share|improve this answer












      Using awk:



      echo "12,1234,28-07-2018 05:28:12.21,ABC60,3456,28-07-2018 05:28:12.21,AB60,7580,28-07-2018 06:28:12.21,PQ" | awk -F ',' 'for (i=1;i<=NF;i++) if($i !~ "-") printf "%s,",$i' 

      12,1234,ABC60,3456,AB60,7580,PQ,


      • prints the columns which are not having -






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Sep 5 at 18:10









      msp9011

      3,46643862




      3,46643862











      • Thank you so much. It worked for me
        – UnixLearner
        Sep 12 at 6:34
















      • Thank you so much. It worked for me
        – UnixLearner
        Sep 12 at 6:34















      Thank you so much. It worked for me
      – UnixLearner
      Sep 12 at 6:34




      Thank you so much. It worked for me
      – UnixLearner
      Sep 12 at 6:34












      up vote
      2
      down vote













      Assuming there are no embedded commas inside a comma-delimited field, and that you want to remove columns 3, 6 and 9.



      $ cut -d, -f1,2,4,5,7,8,10 <file
      12,1234,ABC60,3456,AB60,7580,PQ


      The cut command extracts the given columns out of a file. By default, tabs are used as column delimiters, but with -d, we set the delimiter to a comma. The -f option takes the column numbers (or ranges of column numbers) that are to be extracted.



      Using csvcut from CSVkit, which is a real CSV parser, we can also handle fields which contains embedded commas:



      $ csvcut -c 1,2,4,5,7,8,10 file
      12,1234,ABC60,3456,AB60,7580,PQ


      This tool also handles cutting on column names if the file has headers for each column.






      share|improve this answer


























        up vote
        2
        down vote













        Assuming there are no embedded commas inside a comma-delimited field, and that you want to remove columns 3, 6 and 9.



        $ cut -d, -f1,2,4,5,7,8,10 <file
        12,1234,ABC60,3456,AB60,7580,PQ


        The cut command extracts the given columns out of a file. By default, tabs are used as column delimiters, but with -d, we set the delimiter to a comma. The -f option takes the column numbers (or ranges of column numbers) that are to be extracted.



        Using csvcut from CSVkit, which is a real CSV parser, we can also handle fields which contains embedded commas:



        $ csvcut -c 1,2,4,5,7,8,10 file
        12,1234,ABC60,3456,AB60,7580,PQ


        This tool also handles cutting on column names if the file has headers for each column.






        share|improve this answer
























          up vote
          2
          down vote










          up vote
          2
          down vote









          Assuming there are no embedded commas inside a comma-delimited field, and that you want to remove columns 3, 6 and 9.



          $ cut -d, -f1,2,4,5,7,8,10 <file
          12,1234,ABC60,3456,AB60,7580,PQ


          The cut command extracts the given columns out of a file. By default, tabs are used as column delimiters, but with -d, we set the delimiter to a comma. The -f option takes the column numbers (or ranges of column numbers) that are to be extracted.



          Using csvcut from CSVkit, which is a real CSV parser, we can also handle fields which contains embedded commas:



          $ csvcut -c 1,2,4,5,7,8,10 file
          12,1234,ABC60,3456,AB60,7580,PQ


          This tool also handles cutting on column names if the file has headers for each column.






          share|improve this answer














          Assuming there are no embedded commas inside a comma-delimited field, and that you want to remove columns 3, 6 and 9.



          $ cut -d, -f1,2,4,5,7,8,10 <file
          12,1234,ABC60,3456,AB60,7580,PQ


          The cut command extracts the given columns out of a file. By default, tabs are used as column delimiters, but with -d, we set the delimiter to a comma. The -f option takes the column numbers (or ranges of column numbers) that are to be extracted.



          Using csvcut from CSVkit, which is a real CSV parser, we can also handle fields which contains embedded commas:



          $ csvcut -c 1,2,4,5,7,8,10 file
          12,1234,ABC60,3456,AB60,7580,PQ


          This tool also handles cutting on column names if the file has headers for each column.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Sep 5 at 22:04

























          answered Sep 5 at 19:54









          Kusalananda

          107k14209331




          107k14209331




















              up vote
              1
              down vote













              Albeit not awk, but...



              tr ',' 'n' < csv | grep -E -v '^[0-9]2-[0-9]2-[0-9]4' | tr 'n' ','
              12,1234,ABC60,3456,AB60,7580,PQ,





              share|improve this answer
























                up vote
                1
                down vote













                Albeit not awk, but...



                tr ',' 'n' < csv | grep -E -v '^[0-9]2-[0-9]2-[0-9]4' | tr 'n' ','
                12,1234,ABC60,3456,AB60,7580,PQ,





                share|improve this answer






















                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  Albeit not awk, but...



                  tr ',' 'n' < csv | grep -E -v '^[0-9]2-[0-9]2-[0-9]4' | tr 'n' ','
                  12,1234,ABC60,3456,AB60,7580,PQ,





                  share|improve this answer












                  Albeit not awk, but...



                  tr ',' 'n' < csv | grep -E -v '^[0-9]2-[0-9]2-[0-9]4' | tr 'n' ','
                  12,1234,ABC60,3456,AB60,7580,PQ,






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 5 at 19:31









                  maulinglawns

                  6,12621225




                  6,12621225












                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay