Is there a robust command line tool for processing csv files?












44















I work with CSV files and sometimes need to quickly check the contents of a row or column from the command line. In many cases cut, head, tail, and friends will do the job; however, cut cannot easily deal with situations such as



"this, is the first entry", this is the second, 34.5


Here, the first comma is part of the first field, but cut -d, -f1 disagrees. Before I write a solution myself, I was wondering if anyone knew of a good tool that already exists for this job. It would have to, at the very least, be able to handle the example above and return a column from a CSV formatted file. Other desirable features include the ability to select columns based on the column names given in the first row, support for other quoting styles and support for tab-separated files.



If you don't know of such a tool but have suggestions regarding implementing such a program in Bash, Perl, or Python, or other common scripting languages, I wouldn't mind such suggestions.










share|improve this question





























    44















    I work with CSV files and sometimes need to quickly check the contents of a row or column from the command line. In many cases cut, head, tail, and friends will do the job; however, cut cannot easily deal with situations such as



    "this, is the first entry", this is the second, 34.5


    Here, the first comma is part of the first field, but cut -d, -f1 disagrees. Before I write a solution myself, I was wondering if anyone knew of a good tool that already exists for this job. It would have to, at the very least, be able to handle the example above and return a column from a CSV formatted file. Other desirable features include the ability to select columns based on the column names given in the first row, support for other quoting styles and support for tab-separated files.



    If you don't know of such a tool but have suggestions regarding implementing such a program in Bash, Perl, or Python, or other common scripting languages, I wouldn't mind such suggestions.










    share|improve this question



























      44












      44








      44


      18






      I work with CSV files and sometimes need to quickly check the contents of a row or column from the command line. In many cases cut, head, tail, and friends will do the job; however, cut cannot easily deal with situations such as



      "this, is the first entry", this is the second, 34.5


      Here, the first comma is part of the first field, but cut -d, -f1 disagrees. Before I write a solution myself, I was wondering if anyone knew of a good tool that already exists for this job. It would have to, at the very least, be able to handle the example above and return a column from a CSV formatted file. Other desirable features include the ability to select columns based on the column names given in the first row, support for other quoting styles and support for tab-separated files.



      If you don't know of such a tool but have suggestions regarding implementing such a program in Bash, Perl, or Python, or other common scripting languages, I wouldn't mind such suggestions.










      share|improve this question
















      I work with CSV files and sometimes need to quickly check the contents of a row or column from the command line. In many cases cut, head, tail, and friends will do the job; however, cut cannot easily deal with situations such as



      "this, is the first entry", this is the second, 34.5


      Here, the first comma is part of the first field, but cut -d, -f1 disagrees. Before I write a solution myself, I was wondering if anyone knew of a good tool that already exists for this job. It would have to, at the very least, be able to handle the example above and return a column from a CSV formatted file. Other desirable features include the ability to select columns based on the column names given in the first row, support for other quoting styles and support for tab-separated files.



      If you don't know of such a tool but have suggestions regarding implementing such a program in Bash, Perl, or Python, or other common scripting languages, I wouldn't mind such suggestions.







      command-line software-rec text-processing csv






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 15 '11 at 8:03







      Steven D

















      asked Feb 15 '11 at 7:55









      Steven DSteven D

      32.1k797108




      32.1k797108






















          18 Answers
          18






          active

          oldest

          votes


















          35














          You can use Python's csv module.



          A simple example:



          import csv
          reader = csv.reader(open("test.csv", "rb"))
          for row in reader:
          for col in row:
          print col





          share|improve this answer



















          • 2





            Even better, use Pandas. It is explicitly designed to work with tabular data.

            – Josh
            Jul 15 '14 at 19:24








          • 2





            there is no reason beside regular expression to use perl anyway, and regex are not the answer this time

            – pqnet
            Aug 12 '14 at 5:58






          • 1





            @pqnet "there is no reason beside regular expression to use perl anyway" -- troll much?

            – jrw32982
            Jun 22 '15 at 16:38






          • 3





            @jrw32982 No trolling, I honestly believe there is some truth in the sentence "he had a problem, he decided to solve it with perl, now he has two problems". I would suggest against perl except if your problem is based on regular language parsing, and that's almost never the case.

            – pqnet
            Jun 23 '15 at 15:41






          • 2





            @pqnet so you mean: "for me there is no reason to use perl other than regexp" - that's a reasonable statement. For the rest of the world, your original statement was just a troll.

            – jrw32982
            Jun 23 '15 at 19:39



















          35














          I am probably a little bit too late, but there is another tool worth mentioning: csvkit



          http://csvkit.readthedocs.org/



          It has a lot of command line tools that can:




          • convert to and from csv from various formats (json, sql, xls)

          • cut, grep, sort and others

          • join different csv files!






          share|improve this answer



















          • 5





            An excellent tool that meets the question criteria wonderfully (in particular it doesn't require jumping into a programming language and is well crafted to fit with other Unix utilities).

            – mm2001
            Nov 4 '14 at 20:10



















          15














          Sounds like a job for Perl with Text::CSV.



          perl -MText::CSV -pe '
          BEGIN {$csv = Text::CSV->new();}
          $csv->parse($_) or die;
          @fields = $csv->fields();
          print @fields[1,3];
          '


          See the documentation for how to handle column names. The separator and quoting style can be tuned with parameters to new. See also Text::CSV::Separator for separator guessing.






          share|improve this answer
























          • Is there a one liner you can compact this into. I like perl, but only when I can invoke it directly from the command line rather than with a script

            – user7000
            Jan 26 '17 at 6:04






          • 1





            @user7000, unless your shell is (t)csh that command would work just fine at the prompt of your shell. You can always joins those lines together if you want it on one line. newline is generally just like space in the perl syntax like in C.

            – Stéphane Chazelas
            Sep 12 '17 at 12:07











          • I guess. Though squashing more than 2 lines into 1 isn't what I really mean by a one liner. I was hoping there was some syntactic sugar that would do some of it implicitly (like how the -e creates an implicit loop).

            – user7000
            Sep 12 '17 at 22:33



















          10














          I've found csvfix, a command line tool does the job well. You will need to make it yourself however:



          http://neilb.bitbucket.org/csvfix



          It does all the things you'd expect, order/select columns, split/merge and many you wouldn't like generating SQL inserts from CSV data and diffing CSV data.






          share|improve this answer

































            6














            R is not my favorite programming language, but it is good for things like this.
            If your csv file is



            ***********
            foo.csv
            ***********
            col1, col2, col3
            "this, is the first entry", this is the second, 34.5
            'some more', "messed up", stuff


            Inside the R interpreter type



            > x=read.csv("foo.csv", header=FALSE)

            > x
            col1 col2 col3
            1 this, is the first entry this is the second 34.5
            2 'some more' messed up stuff
            > x[1] # first col
            col1
            1 this, is the first entry
            2 'some more'
            > x[1,] # first row
            col1 col2 col3
            1 this, is the first entry this is the second 34.5


            With regard to your other requests, for "the ability to select columns based on the column names given in the first row" see



            > x["col1"]
            col1
            1 this, is the first entry
            2 'some more'


            For "support for other quoting styles" see the quote argument to read.csv (and related functions).
            For "support for tab-separated files" see the sep argument to read.csv (set sep to 't').



            For more information see the online help.



            > help(read.csv)





            share|improve this answer


























            • I'm very familiar with R, but my goal was to have something I could use easily from Bash.

              – Steven D
              Apr 6 '11 at 15:03






            • 1





              @Steven: R can easily be run from the command line, in the same way as Python or Perl, if that is your only concern. See Rscript (part of the base R distribution) or the addon package littler. You can do #!/usr/bin/env Rscript or similar.

              – Faheem Mitha
              Apr 7 '11 at 18:21













            • Ah yes. I'm pretty proficient in R but hadn't used it much to create this type of utility. I have something working in Python but I may try to create something in R as well.

              – Steven D
              Apr 10 '11 at 1:05



















            6














            I used csvtool once and it saved me a lot of time and trouble. Callable from the shell.



            http://caml.inria.fr/cgi-bin/hump.en.cgi?contrib=447






            share|improve this answer































              6














              If you want to use the command-line (and do not create an entire program to do the job), you'd like to use rows, a project I'm working on: it's a command-line interface to tabular data but also a Python library to use in your programs. With the command-line interface you can pretty-print any data in CSV, XLS, XLSX, HTML or any other tabular format supported by the library with a simple command:



              rows print myfile.csv


              If myfile.csv is like this:



              state,city,inhabitants,area
              RJ,Angra dos Reis,169511,825.09
              RJ,Aperibé,10213,94.64
              RJ,Araruama,112008,638.02
              RJ,Areal,11423,110.92
              RJ,Armação dos Búzios,27560,70.28


              Then rows will print the contents in a beautiful way, like this:



              +-------+-------------------------------+-------------+---------+
              | state | city | inhabitants | area |
              +-------+-------------------------------+-------------+---------+
              | RJ | Angra dos Reis | 169511 | 825.09 |
              | RJ | Aperibé | 10213 | 94.64 |
              | RJ | Araruama | 112008 | 638.02 |
              | RJ | Areal | 11423 | 110.92 |
              | RJ | Armação dos Búzios | 27560 | 70.28 |
              +-------+-------------------------------+-------------+---------+


              Installing



              If you are a Python developer and already have pip installed on your machine, just run inside a virtualenv or with sudo:



              pip install rows


              If you're using Debian:



              sudo apt-get install rows


              Other Cool Features



              Converting Formats



              You can convert between any supported format:



              rows convert myfile.xlsx myfile.csv


              Querying



              Yes, you can use SQL into a CSV file:



              $ rows query 'SELECT city, area FROM table1 WHERE inhabitants > 100000' myfile.csv
              +----------------+--------+
              | city | area |
              +----------------+--------+
              | Angra dos Reis | 825.09 |
              | Araruama | 638.02 |
              +----------------+--------+


              Converting the output of the query to a file instead of stdout is also possible using the --output parameter.



              As a Python Library



              You can you in your Python programs too:



              import rows
              table = rows.import_from_csv('myfile.csv')
              rows.export_to_txt(table, 'myfile.txt')
              # `myfile.txt` will have same content as `rows print` output


              Hope you enjoy it!






              share|improve this answer

































                4














                Or, you could try some awk magic.
                Howewer, I'm not a good awk user and cannot confirm this would work properly, and how to do it.






                share|improve this answer



















                • 9





                  Here is one awk CSV Parser I used a while back.. It seems quite well thought out... lorance.freeshell.org/csv

                  – Peter.O
                  Feb 15 '11 at 14:11



















                3














                Have a look also at GNU Recutils and crush-tools.



                (via http://www.reddit.com/r/commandline/comments/mfcu9/anyone_using_gnu_recutils_is_it_outdatedsuperceded/)






                share|improve this answer































                  3














                  Miller is another nice tool for manipulating name-based data, including CSV (with headers). To extract the first column of a CSV file, without caring about its name, you’d do something like



                  printf '"first,column",second,thirdn1,2,3n' |
                  mlr --csv --implicit-csv-header --headerless-csv-output cut -f 1





                  share|improve this answer


























                  • Miller is very impressive. I'd compare it to awk, but highly DSV-aware.

                    – Derek Mahar
                    Apr 18 '18 at 21:59



















                  2














                  To use python from the command line, you can check out pythonpy (https://github.com/Russell91/pythonpy):



                  $ echo $'a,b,cnd,e,f' | py '[x[1] for x in csv.reader(sys.stdin)']
                  b
                  e





                  share|improve this answer































                    2














                    try "csvtool" this package
                    it's handy command line tool for handling CSV files






                    share|improve this answer



















                    • 1





                      Already mentioned, with more detail...

                      – jasonwryan
                      Sep 3 '15 at 9:27



















                    2














                    cissy will also do command-line csv processing. It's written in C (small/lightweight) with rpm and deb packages available for most distros.



                    Using the example:



                    echo '"this, is the first entry", this is the second, 34.5' | cissy -c 1
                    "this, is the first entry"


                    or



                    echo '"this, is the first entry", this is the second, 34.5' | cissy -c 2
                    this is the second


                    or



                    echo '"this, is the first entry", this is the second, 34.5' | cissy -c 2-
                    this is the second, 34.5





                    share|improve this answer

































                      1














                      There is also a Curry library for reading/writing files in CSV format: CSV.






                      share|improve this answer



















                      • 2





                        Would you mind posting some sample code, like the Perl, Python and R answers? (Especially since Curry is not a common unix scripting language.)

                        – Gilles
                        Apr 20 '11 at 21:31











                      • @Gilles: Yes, you are right, I should post some sample code to make the answer better. I'm going to do this in a while.

                        – imz -- Ivan Zakharyaschev
                        Apr 20 '11 at 21:36



















                      1














                      The github repo Structured Text Tools has a useful list of relevant linux command line tools. In particular, the Delimiter Separated Values section lists several CSV capable tools that directly support the operations requested.






                      share|improve this answer































                        0














                        An awk solution



                        awk -vq='"' '
                        func csv2del(n) {
                        for(i=n; i<=c; i++)
                        {if(i%2 == 1) gsub(/,/, OFS, a[i])
                        else a[i] = (q a[i] q)
                        out = (out) ? out a[i] : a[i]}
                        return out}
                        {c=split($0, a, q); out=X;
                        if(a[1]) $0=csv2del(1)
                        else $0=csv2del(2)}1' OFS='|' file





                        share|improve this answer































                          0














                          I'd recommend xsv - A fast CSV command line toolkit written in Rust (Github).



                          Written by Ripgrep's author.



                          Featured in How we made our CSV processing 142x faster (Reddit thread).






                          share|improve this answer































                            0














                            One of the best tool is Miller (http://johnkerl.org/miller/doc/index.html). It is like awk, sed, cut, join, and sort for name-indexed data such as CSV, TSV, and tabular JSON.



                            In example



                            echo '"this, is the first entry", this is the second, 34.5' | 
                            mlr --icsv --implicit-csv-header cat


                            gives you



                            1=this, is the first entry,2= this is the second,3= 34.5


                            If you want a TSV



                            echo '"this, is the first entry", this is the second, 34.5' |
                            mlr --c2t --implicit-csv-header cat



                            gives you (it's possible to remove the header)



                            1       2       3
                            this, is the first entry this is the second 34.5


                            If you want first and third column, changing their order



                            echo '"this, is the first entry", this is the second, 34.5' | 
                            mlr --csv --implicit-csv-header --headerless-csv-output cut -o -f 3,1


                            gives you



                             34.5,"this, is the first entry"




                            share























                              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%2f7425%2fis-there-a-robust-command-line-tool-for-processing-csv-files%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown

























                              18 Answers
                              18






                              active

                              oldest

                              votes








                              18 Answers
                              18






                              active

                              oldest

                              votes









                              active

                              oldest

                              votes






                              active

                              oldest

                              votes









                              35














                              You can use Python's csv module.



                              A simple example:



                              import csv
                              reader = csv.reader(open("test.csv", "rb"))
                              for row in reader:
                              for col in row:
                              print col





                              share|improve this answer



















                              • 2





                                Even better, use Pandas. It is explicitly designed to work with tabular data.

                                – Josh
                                Jul 15 '14 at 19:24








                              • 2





                                there is no reason beside regular expression to use perl anyway, and regex are not the answer this time

                                – pqnet
                                Aug 12 '14 at 5:58






                              • 1





                                @pqnet "there is no reason beside regular expression to use perl anyway" -- troll much?

                                – jrw32982
                                Jun 22 '15 at 16:38






                              • 3





                                @jrw32982 No trolling, I honestly believe there is some truth in the sentence "he had a problem, he decided to solve it with perl, now he has two problems". I would suggest against perl except if your problem is based on regular language parsing, and that's almost never the case.

                                – pqnet
                                Jun 23 '15 at 15:41






                              • 2





                                @pqnet so you mean: "for me there is no reason to use perl other than regexp" - that's a reasonable statement. For the rest of the world, your original statement was just a troll.

                                – jrw32982
                                Jun 23 '15 at 19:39
















                              35














                              You can use Python's csv module.



                              A simple example:



                              import csv
                              reader = csv.reader(open("test.csv", "rb"))
                              for row in reader:
                              for col in row:
                              print col





                              share|improve this answer



















                              • 2





                                Even better, use Pandas. It is explicitly designed to work with tabular data.

                                – Josh
                                Jul 15 '14 at 19:24








                              • 2





                                there is no reason beside regular expression to use perl anyway, and regex are not the answer this time

                                – pqnet
                                Aug 12 '14 at 5:58






                              • 1





                                @pqnet "there is no reason beside regular expression to use perl anyway" -- troll much?

                                – jrw32982
                                Jun 22 '15 at 16:38






                              • 3





                                @jrw32982 No trolling, I honestly believe there is some truth in the sentence "he had a problem, he decided to solve it with perl, now he has two problems". I would suggest against perl except if your problem is based on regular language parsing, and that's almost never the case.

                                – pqnet
                                Jun 23 '15 at 15:41






                              • 2





                                @pqnet so you mean: "for me there is no reason to use perl other than regexp" - that's a reasonable statement. For the rest of the world, your original statement was just a troll.

                                – jrw32982
                                Jun 23 '15 at 19:39














                              35












                              35








                              35







                              You can use Python's csv module.



                              A simple example:



                              import csv
                              reader = csv.reader(open("test.csv", "rb"))
                              for row in reader:
                              for col in row:
                              print col





                              share|improve this answer













                              You can use Python's csv module.



                              A simple example:



                              import csv
                              reader = csv.reader(open("test.csv", "rb"))
                              for row in reader:
                              for col in row:
                              print col






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Feb 15 '11 at 8:56









                              dogbanedogbane

                              14.1k96458




                              14.1k96458








                              • 2





                                Even better, use Pandas. It is explicitly designed to work with tabular data.

                                – Josh
                                Jul 15 '14 at 19:24








                              • 2





                                there is no reason beside regular expression to use perl anyway, and regex are not the answer this time

                                – pqnet
                                Aug 12 '14 at 5:58






                              • 1





                                @pqnet "there is no reason beside regular expression to use perl anyway" -- troll much?

                                – jrw32982
                                Jun 22 '15 at 16:38






                              • 3





                                @jrw32982 No trolling, I honestly believe there is some truth in the sentence "he had a problem, he decided to solve it with perl, now he has two problems". I would suggest against perl except if your problem is based on regular language parsing, and that's almost never the case.

                                – pqnet
                                Jun 23 '15 at 15:41






                              • 2





                                @pqnet so you mean: "for me there is no reason to use perl other than regexp" - that's a reasonable statement. For the rest of the world, your original statement was just a troll.

                                – jrw32982
                                Jun 23 '15 at 19:39














                              • 2





                                Even better, use Pandas. It is explicitly designed to work with tabular data.

                                – Josh
                                Jul 15 '14 at 19:24








                              • 2





                                there is no reason beside regular expression to use perl anyway, and regex are not the answer this time

                                – pqnet
                                Aug 12 '14 at 5:58






                              • 1





                                @pqnet "there is no reason beside regular expression to use perl anyway" -- troll much?

                                – jrw32982
                                Jun 22 '15 at 16:38






                              • 3





                                @jrw32982 No trolling, I honestly believe there is some truth in the sentence "he had a problem, he decided to solve it with perl, now he has two problems". I would suggest against perl except if your problem is based on regular language parsing, and that's almost never the case.

                                – pqnet
                                Jun 23 '15 at 15:41






                              • 2





                                @pqnet so you mean: "for me there is no reason to use perl other than regexp" - that's a reasonable statement. For the rest of the world, your original statement was just a troll.

                                – jrw32982
                                Jun 23 '15 at 19:39








                              2




                              2





                              Even better, use Pandas. It is explicitly designed to work with tabular data.

                              – Josh
                              Jul 15 '14 at 19:24







                              Even better, use Pandas. It is explicitly designed to work with tabular data.

                              – Josh
                              Jul 15 '14 at 19:24






                              2




                              2





                              there is no reason beside regular expression to use perl anyway, and regex are not the answer this time

                              – pqnet
                              Aug 12 '14 at 5:58





                              there is no reason beside regular expression to use perl anyway, and regex are not the answer this time

                              – pqnet
                              Aug 12 '14 at 5:58




                              1




                              1





                              @pqnet "there is no reason beside regular expression to use perl anyway" -- troll much?

                              – jrw32982
                              Jun 22 '15 at 16:38





                              @pqnet "there is no reason beside regular expression to use perl anyway" -- troll much?

                              – jrw32982
                              Jun 22 '15 at 16:38




                              3




                              3





                              @jrw32982 No trolling, I honestly believe there is some truth in the sentence "he had a problem, he decided to solve it with perl, now he has two problems". I would suggest against perl except if your problem is based on regular language parsing, and that's almost never the case.

                              – pqnet
                              Jun 23 '15 at 15:41





                              @jrw32982 No trolling, I honestly believe there is some truth in the sentence "he had a problem, he decided to solve it with perl, now he has two problems". I would suggest against perl except if your problem is based on regular language parsing, and that's almost never the case.

                              – pqnet
                              Jun 23 '15 at 15:41




                              2




                              2





                              @pqnet so you mean: "for me there is no reason to use perl other than regexp" - that's a reasonable statement. For the rest of the world, your original statement was just a troll.

                              – jrw32982
                              Jun 23 '15 at 19:39





                              @pqnet so you mean: "for me there is no reason to use perl other than regexp" - that's a reasonable statement. For the rest of the world, your original statement was just a troll.

                              – jrw32982
                              Jun 23 '15 at 19:39













                              35














                              I am probably a little bit too late, but there is another tool worth mentioning: csvkit



                              http://csvkit.readthedocs.org/



                              It has a lot of command line tools that can:




                              • convert to and from csv from various formats (json, sql, xls)

                              • cut, grep, sort and others

                              • join different csv files!






                              share|improve this answer



















                              • 5





                                An excellent tool that meets the question criteria wonderfully (in particular it doesn't require jumping into a programming language and is well crafted to fit with other Unix utilities).

                                – mm2001
                                Nov 4 '14 at 20:10
















                              35














                              I am probably a little bit too late, but there is another tool worth mentioning: csvkit



                              http://csvkit.readthedocs.org/



                              It has a lot of command line tools that can:




                              • convert to and from csv from various formats (json, sql, xls)

                              • cut, grep, sort and others

                              • join different csv files!






                              share|improve this answer



















                              • 5





                                An excellent tool that meets the question criteria wonderfully (in particular it doesn't require jumping into a programming language and is well crafted to fit with other Unix utilities).

                                – mm2001
                                Nov 4 '14 at 20:10














                              35












                              35








                              35







                              I am probably a little bit too late, but there is another tool worth mentioning: csvkit



                              http://csvkit.readthedocs.org/



                              It has a lot of command line tools that can:




                              • convert to and from csv from various formats (json, sql, xls)

                              • cut, grep, sort and others

                              • join different csv files!






                              share|improve this answer













                              I am probably a little bit too late, but there is another tool worth mentioning: csvkit



                              http://csvkit.readthedocs.org/



                              It has a lot of command line tools that can:




                              • convert to and from csv from various formats (json, sql, xls)

                              • cut, grep, sort and others

                              • join different csv files!







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Jul 15 '14 at 17:18









                              romaiaromaia

                              45144




                              45144








                              • 5





                                An excellent tool that meets the question criteria wonderfully (in particular it doesn't require jumping into a programming language and is well crafted to fit with other Unix utilities).

                                – mm2001
                                Nov 4 '14 at 20:10














                              • 5





                                An excellent tool that meets the question criteria wonderfully (in particular it doesn't require jumping into a programming language and is well crafted to fit with other Unix utilities).

                                – mm2001
                                Nov 4 '14 at 20:10








                              5




                              5





                              An excellent tool that meets the question criteria wonderfully (in particular it doesn't require jumping into a programming language and is well crafted to fit with other Unix utilities).

                              – mm2001
                              Nov 4 '14 at 20:10





                              An excellent tool that meets the question criteria wonderfully (in particular it doesn't require jumping into a programming language and is well crafted to fit with other Unix utilities).

                              – mm2001
                              Nov 4 '14 at 20:10











                              15














                              Sounds like a job for Perl with Text::CSV.



                              perl -MText::CSV -pe '
                              BEGIN {$csv = Text::CSV->new();}
                              $csv->parse($_) or die;
                              @fields = $csv->fields();
                              print @fields[1,3];
                              '


                              See the documentation for how to handle column names. The separator and quoting style can be tuned with parameters to new. See also Text::CSV::Separator for separator guessing.






                              share|improve this answer
























                              • Is there a one liner you can compact this into. I like perl, but only when I can invoke it directly from the command line rather than with a script

                                – user7000
                                Jan 26 '17 at 6:04






                              • 1





                                @user7000, unless your shell is (t)csh that command would work just fine at the prompt of your shell. You can always joins those lines together if you want it on one line. newline is generally just like space in the perl syntax like in C.

                                – Stéphane Chazelas
                                Sep 12 '17 at 12:07











                              • I guess. Though squashing more than 2 lines into 1 isn't what I really mean by a one liner. I was hoping there was some syntactic sugar that would do some of it implicitly (like how the -e creates an implicit loop).

                                – user7000
                                Sep 12 '17 at 22:33
















                              15














                              Sounds like a job for Perl with Text::CSV.



                              perl -MText::CSV -pe '
                              BEGIN {$csv = Text::CSV->new();}
                              $csv->parse($_) or die;
                              @fields = $csv->fields();
                              print @fields[1,3];
                              '


                              See the documentation for how to handle column names. The separator and quoting style can be tuned with parameters to new. See also Text::CSV::Separator for separator guessing.






                              share|improve this answer
























                              • Is there a one liner you can compact this into. I like perl, but only when I can invoke it directly from the command line rather than with a script

                                – user7000
                                Jan 26 '17 at 6:04






                              • 1





                                @user7000, unless your shell is (t)csh that command would work just fine at the prompt of your shell. You can always joins those lines together if you want it on one line. newline is generally just like space in the perl syntax like in C.

                                – Stéphane Chazelas
                                Sep 12 '17 at 12:07











                              • I guess. Though squashing more than 2 lines into 1 isn't what I really mean by a one liner. I was hoping there was some syntactic sugar that would do some of it implicitly (like how the -e creates an implicit loop).

                                – user7000
                                Sep 12 '17 at 22:33














                              15












                              15








                              15







                              Sounds like a job for Perl with Text::CSV.



                              perl -MText::CSV -pe '
                              BEGIN {$csv = Text::CSV->new();}
                              $csv->parse($_) or die;
                              @fields = $csv->fields();
                              print @fields[1,3];
                              '


                              See the documentation for how to handle column names. The separator and quoting style can be tuned with parameters to new. See also Text::CSV::Separator for separator guessing.






                              share|improve this answer













                              Sounds like a job for Perl with Text::CSV.



                              perl -MText::CSV -pe '
                              BEGIN {$csv = Text::CSV->new();}
                              $csv->parse($_) or die;
                              @fields = $csv->fields();
                              print @fields[1,3];
                              '


                              See the documentation for how to handle column names. The separator and quoting style can be tuned with parameters to new. See also Text::CSV::Separator for separator guessing.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Feb 15 '11 at 8:31









                              GillesGilles

                              532k12810661592




                              532k12810661592













                              • Is there a one liner you can compact this into. I like perl, but only when I can invoke it directly from the command line rather than with a script

                                – user7000
                                Jan 26 '17 at 6:04






                              • 1





                                @user7000, unless your shell is (t)csh that command would work just fine at the prompt of your shell. You can always joins those lines together if you want it on one line. newline is generally just like space in the perl syntax like in C.

                                – Stéphane Chazelas
                                Sep 12 '17 at 12:07











                              • I guess. Though squashing more than 2 lines into 1 isn't what I really mean by a one liner. I was hoping there was some syntactic sugar that would do some of it implicitly (like how the -e creates an implicit loop).

                                – user7000
                                Sep 12 '17 at 22:33



















                              • Is there a one liner you can compact this into. I like perl, but only when I can invoke it directly from the command line rather than with a script

                                – user7000
                                Jan 26 '17 at 6:04






                              • 1





                                @user7000, unless your shell is (t)csh that command would work just fine at the prompt of your shell. You can always joins those lines together if you want it on one line. newline is generally just like space in the perl syntax like in C.

                                – Stéphane Chazelas
                                Sep 12 '17 at 12:07











                              • I guess. Though squashing more than 2 lines into 1 isn't what I really mean by a one liner. I was hoping there was some syntactic sugar that would do some of it implicitly (like how the -e creates an implicit loop).

                                – user7000
                                Sep 12 '17 at 22:33

















                              Is there a one liner you can compact this into. I like perl, but only when I can invoke it directly from the command line rather than with a script

                              – user7000
                              Jan 26 '17 at 6:04





                              Is there a one liner you can compact this into. I like perl, but only when I can invoke it directly from the command line rather than with a script

                              – user7000
                              Jan 26 '17 at 6:04




                              1




                              1





                              @user7000, unless your shell is (t)csh that command would work just fine at the prompt of your shell. You can always joins those lines together if you want it on one line. newline is generally just like space in the perl syntax like in C.

                              – Stéphane Chazelas
                              Sep 12 '17 at 12:07





                              @user7000, unless your shell is (t)csh that command would work just fine at the prompt of your shell. You can always joins those lines together if you want it on one line. newline is generally just like space in the perl syntax like in C.

                              – Stéphane Chazelas
                              Sep 12 '17 at 12:07













                              I guess. Though squashing more than 2 lines into 1 isn't what I really mean by a one liner. I was hoping there was some syntactic sugar that would do some of it implicitly (like how the -e creates an implicit loop).

                              – user7000
                              Sep 12 '17 at 22:33





                              I guess. Though squashing more than 2 lines into 1 isn't what I really mean by a one liner. I was hoping there was some syntactic sugar that would do some of it implicitly (like how the -e creates an implicit loop).

                              – user7000
                              Sep 12 '17 at 22:33











                              10














                              I've found csvfix, a command line tool does the job well. You will need to make it yourself however:



                              http://neilb.bitbucket.org/csvfix



                              It does all the things you'd expect, order/select columns, split/merge and many you wouldn't like generating SQL inserts from CSV data and diffing CSV data.






                              share|improve this answer






























                                10














                                I've found csvfix, a command line tool does the job well. You will need to make it yourself however:



                                http://neilb.bitbucket.org/csvfix



                                It does all the things you'd expect, order/select columns, split/merge and many you wouldn't like generating SQL inserts from CSV data and diffing CSV data.






                                share|improve this answer




























                                  10












                                  10








                                  10







                                  I've found csvfix, a command line tool does the job well. You will need to make it yourself however:



                                  http://neilb.bitbucket.org/csvfix



                                  It does all the things you'd expect, order/select columns, split/merge and many you wouldn't like generating SQL inserts from CSV data and diffing CSV data.






                                  share|improve this answer















                                  I've found csvfix, a command line tool does the job well. You will need to make it yourself however:



                                  http://neilb.bitbucket.org/csvfix



                                  It does all the things you'd expect, order/select columns, split/merge and many you wouldn't like generating SQL inserts from CSV data and diffing CSV data.







                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Jun 15 '15 at 15:09









                                  Community

                                  1




                                  1










                                  answered Sep 21 '11 at 15:17









                                  Daniel BurkeDaniel Burke

                                  10112




                                  10112























                                      6














                                      R is not my favorite programming language, but it is good for things like this.
                                      If your csv file is



                                      ***********
                                      foo.csv
                                      ***********
                                      col1, col2, col3
                                      "this, is the first entry", this is the second, 34.5
                                      'some more', "messed up", stuff


                                      Inside the R interpreter type



                                      > x=read.csv("foo.csv", header=FALSE)

                                      > x
                                      col1 col2 col3
                                      1 this, is the first entry this is the second 34.5
                                      2 'some more' messed up stuff
                                      > x[1] # first col
                                      col1
                                      1 this, is the first entry
                                      2 'some more'
                                      > x[1,] # first row
                                      col1 col2 col3
                                      1 this, is the first entry this is the second 34.5


                                      With regard to your other requests, for "the ability to select columns based on the column names given in the first row" see



                                      > x["col1"]
                                      col1
                                      1 this, is the first entry
                                      2 'some more'


                                      For "support for other quoting styles" see the quote argument to read.csv (and related functions).
                                      For "support for tab-separated files" see the sep argument to read.csv (set sep to 't').



                                      For more information see the online help.



                                      > help(read.csv)





                                      share|improve this answer


























                                      • I'm very familiar with R, but my goal was to have something I could use easily from Bash.

                                        – Steven D
                                        Apr 6 '11 at 15:03






                                      • 1





                                        @Steven: R can easily be run from the command line, in the same way as Python or Perl, if that is your only concern. See Rscript (part of the base R distribution) or the addon package littler. You can do #!/usr/bin/env Rscript or similar.

                                        – Faheem Mitha
                                        Apr 7 '11 at 18:21













                                      • Ah yes. I'm pretty proficient in R but hadn't used it much to create this type of utility. I have something working in Python but I may try to create something in R as well.

                                        – Steven D
                                        Apr 10 '11 at 1:05
















                                      6














                                      R is not my favorite programming language, but it is good for things like this.
                                      If your csv file is



                                      ***********
                                      foo.csv
                                      ***********
                                      col1, col2, col3
                                      "this, is the first entry", this is the second, 34.5
                                      'some more', "messed up", stuff


                                      Inside the R interpreter type



                                      > x=read.csv("foo.csv", header=FALSE)

                                      > x
                                      col1 col2 col3
                                      1 this, is the first entry this is the second 34.5
                                      2 'some more' messed up stuff
                                      > x[1] # first col
                                      col1
                                      1 this, is the first entry
                                      2 'some more'
                                      > x[1,] # first row
                                      col1 col2 col3
                                      1 this, is the first entry this is the second 34.5


                                      With regard to your other requests, for "the ability to select columns based on the column names given in the first row" see



                                      > x["col1"]
                                      col1
                                      1 this, is the first entry
                                      2 'some more'


                                      For "support for other quoting styles" see the quote argument to read.csv (and related functions).
                                      For "support for tab-separated files" see the sep argument to read.csv (set sep to 't').



                                      For more information see the online help.



                                      > help(read.csv)





                                      share|improve this answer


























                                      • I'm very familiar with R, but my goal was to have something I could use easily from Bash.

                                        – Steven D
                                        Apr 6 '11 at 15:03






                                      • 1





                                        @Steven: R can easily be run from the command line, in the same way as Python or Perl, if that is your only concern. See Rscript (part of the base R distribution) or the addon package littler. You can do #!/usr/bin/env Rscript or similar.

                                        – Faheem Mitha
                                        Apr 7 '11 at 18:21













                                      • Ah yes. I'm pretty proficient in R but hadn't used it much to create this type of utility. I have something working in Python but I may try to create something in R as well.

                                        – Steven D
                                        Apr 10 '11 at 1:05














                                      6












                                      6








                                      6







                                      R is not my favorite programming language, but it is good for things like this.
                                      If your csv file is



                                      ***********
                                      foo.csv
                                      ***********
                                      col1, col2, col3
                                      "this, is the first entry", this is the second, 34.5
                                      'some more', "messed up", stuff


                                      Inside the R interpreter type



                                      > x=read.csv("foo.csv", header=FALSE)

                                      > x
                                      col1 col2 col3
                                      1 this, is the first entry this is the second 34.5
                                      2 'some more' messed up stuff
                                      > x[1] # first col
                                      col1
                                      1 this, is the first entry
                                      2 'some more'
                                      > x[1,] # first row
                                      col1 col2 col3
                                      1 this, is the first entry this is the second 34.5


                                      With regard to your other requests, for "the ability to select columns based on the column names given in the first row" see



                                      > x["col1"]
                                      col1
                                      1 this, is the first entry
                                      2 'some more'


                                      For "support for other quoting styles" see the quote argument to read.csv (and related functions).
                                      For "support for tab-separated files" see the sep argument to read.csv (set sep to 't').



                                      For more information see the online help.



                                      > help(read.csv)





                                      share|improve this answer















                                      R is not my favorite programming language, but it is good for things like this.
                                      If your csv file is



                                      ***********
                                      foo.csv
                                      ***********
                                      col1, col2, col3
                                      "this, is the first entry", this is the second, 34.5
                                      'some more', "messed up", stuff


                                      Inside the R interpreter type



                                      > x=read.csv("foo.csv", header=FALSE)

                                      > x
                                      col1 col2 col3
                                      1 this, is the first entry this is the second 34.5
                                      2 'some more' messed up stuff
                                      > x[1] # first col
                                      col1
                                      1 this, is the first entry
                                      2 'some more'
                                      > x[1,] # first row
                                      col1 col2 col3
                                      1 this, is the first entry this is the second 34.5


                                      With regard to your other requests, for "the ability to select columns based on the column names given in the first row" see



                                      > x["col1"]
                                      col1
                                      1 this, is the first entry
                                      2 'some more'


                                      For "support for other quoting styles" see the quote argument to read.csv (and related functions).
                                      For "support for tab-separated files" see the sep argument to read.csv (set sep to 't').



                                      For more information see the online help.



                                      > help(read.csv)






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Apr 1 '11 at 21:52

























                                      answered Apr 1 '11 at 21:33









                                      Faheem MithaFaheem Mitha

                                      22.9k1880135




                                      22.9k1880135













                                      • I'm very familiar with R, but my goal was to have something I could use easily from Bash.

                                        – Steven D
                                        Apr 6 '11 at 15:03






                                      • 1





                                        @Steven: R can easily be run from the command line, in the same way as Python or Perl, if that is your only concern. See Rscript (part of the base R distribution) or the addon package littler. You can do #!/usr/bin/env Rscript or similar.

                                        – Faheem Mitha
                                        Apr 7 '11 at 18:21













                                      • Ah yes. I'm pretty proficient in R but hadn't used it much to create this type of utility. I have something working in Python but I may try to create something in R as well.

                                        – Steven D
                                        Apr 10 '11 at 1:05



















                                      • I'm very familiar with R, but my goal was to have something I could use easily from Bash.

                                        – Steven D
                                        Apr 6 '11 at 15:03






                                      • 1





                                        @Steven: R can easily be run from the command line, in the same way as Python or Perl, if that is your only concern. See Rscript (part of the base R distribution) or the addon package littler. You can do #!/usr/bin/env Rscript or similar.

                                        – Faheem Mitha
                                        Apr 7 '11 at 18:21













                                      • Ah yes. I'm pretty proficient in R but hadn't used it much to create this type of utility. I have something working in Python but I may try to create something in R as well.

                                        – Steven D
                                        Apr 10 '11 at 1:05

















                                      I'm very familiar with R, but my goal was to have something I could use easily from Bash.

                                      – Steven D
                                      Apr 6 '11 at 15:03





                                      I'm very familiar with R, but my goal was to have something I could use easily from Bash.

                                      – Steven D
                                      Apr 6 '11 at 15:03




                                      1




                                      1





                                      @Steven: R can easily be run from the command line, in the same way as Python or Perl, if that is your only concern. See Rscript (part of the base R distribution) or the addon package littler. You can do #!/usr/bin/env Rscript or similar.

                                      – Faheem Mitha
                                      Apr 7 '11 at 18:21







                                      @Steven: R can easily be run from the command line, in the same way as Python or Perl, if that is your only concern. See Rscript (part of the base R distribution) or the addon package littler. You can do #!/usr/bin/env Rscript or similar.

                                      – Faheem Mitha
                                      Apr 7 '11 at 18:21















                                      Ah yes. I'm pretty proficient in R but hadn't used it much to create this type of utility. I have something working in Python but I may try to create something in R as well.

                                      – Steven D
                                      Apr 10 '11 at 1:05





                                      Ah yes. I'm pretty proficient in R but hadn't used it much to create this type of utility. I have something working in Python but I may try to create something in R as well.

                                      – Steven D
                                      Apr 10 '11 at 1:05











                                      6














                                      I used csvtool once and it saved me a lot of time and trouble. Callable from the shell.



                                      http://caml.inria.fr/cgi-bin/hump.en.cgi?contrib=447






                                      share|improve this answer




























                                        6














                                        I used csvtool once and it saved me a lot of time and trouble. Callable from the shell.



                                        http://caml.inria.fr/cgi-bin/hump.en.cgi?contrib=447






                                        share|improve this answer


























                                          6












                                          6








                                          6







                                          I used csvtool once and it saved me a lot of time and trouble. Callable from the shell.



                                          http://caml.inria.fr/cgi-bin/hump.en.cgi?contrib=447






                                          share|improve this answer













                                          I used csvtool once and it saved me a lot of time and trouble. Callable from the shell.



                                          http://caml.inria.fr/cgi-bin/hump.en.cgi?contrib=447







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Sep 21 '11 at 20:27









                                          natnat

                                          6111




                                          6111























                                              6














                                              If you want to use the command-line (and do not create an entire program to do the job), you'd like to use rows, a project I'm working on: it's a command-line interface to tabular data but also a Python library to use in your programs. With the command-line interface you can pretty-print any data in CSV, XLS, XLSX, HTML or any other tabular format supported by the library with a simple command:



                                              rows print myfile.csv


                                              If myfile.csv is like this:



                                              state,city,inhabitants,area
                                              RJ,Angra dos Reis,169511,825.09
                                              RJ,Aperibé,10213,94.64
                                              RJ,Araruama,112008,638.02
                                              RJ,Areal,11423,110.92
                                              RJ,Armação dos Búzios,27560,70.28


                                              Then rows will print the contents in a beautiful way, like this:



                                              +-------+-------------------------------+-------------+---------+
                                              | state | city | inhabitants | area |
                                              +-------+-------------------------------+-------------+---------+
                                              | RJ | Angra dos Reis | 169511 | 825.09 |
                                              | RJ | Aperibé | 10213 | 94.64 |
                                              | RJ | Araruama | 112008 | 638.02 |
                                              | RJ | Areal | 11423 | 110.92 |
                                              | RJ | Armação dos Búzios | 27560 | 70.28 |
                                              +-------+-------------------------------+-------------+---------+


                                              Installing



                                              If you are a Python developer and already have pip installed on your machine, just run inside a virtualenv or with sudo:



                                              pip install rows


                                              If you're using Debian:



                                              sudo apt-get install rows


                                              Other Cool Features



                                              Converting Formats



                                              You can convert between any supported format:



                                              rows convert myfile.xlsx myfile.csv


                                              Querying



                                              Yes, you can use SQL into a CSV file:



                                              $ rows query 'SELECT city, area FROM table1 WHERE inhabitants > 100000' myfile.csv
                                              +----------------+--------+
                                              | city | area |
                                              +----------------+--------+
                                              | Angra dos Reis | 825.09 |
                                              | Araruama | 638.02 |
                                              +----------------+--------+


                                              Converting the output of the query to a file instead of stdout is also possible using the --output parameter.



                                              As a Python Library



                                              You can you in your Python programs too:



                                              import rows
                                              table = rows.import_from_csv('myfile.csv')
                                              rows.export_to_txt(table, 'myfile.txt')
                                              # `myfile.txt` will have same content as `rows print` output


                                              Hope you enjoy it!






                                              share|improve this answer






























                                                6














                                                If you want to use the command-line (and do not create an entire program to do the job), you'd like to use rows, a project I'm working on: it's a command-line interface to tabular data but also a Python library to use in your programs. With the command-line interface you can pretty-print any data in CSV, XLS, XLSX, HTML or any other tabular format supported by the library with a simple command:



                                                rows print myfile.csv


                                                If myfile.csv is like this:



                                                state,city,inhabitants,area
                                                RJ,Angra dos Reis,169511,825.09
                                                RJ,Aperibé,10213,94.64
                                                RJ,Araruama,112008,638.02
                                                RJ,Areal,11423,110.92
                                                RJ,Armação dos Búzios,27560,70.28


                                                Then rows will print the contents in a beautiful way, like this:



                                                +-------+-------------------------------+-------------+---------+
                                                | state | city | inhabitants | area |
                                                +-------+-------------------------------+-------------+---------+
                                                | RJ | Angra dos Reis | 169511 | 825.09 |
                                                | RJ | Aperibé | 10213 | 94.64 |
                                                | RJ | Araruama | 112008 | 638.02 |
                                                | RJ | Areal | 11423 | 110.92 |
                                                | RJ | Armação dos Búzios | 27560 | 70.28 |
                                                +-------+-------------------------------+-------------+---------+


                                                Installing



                                                If you are a Python developer and already have pip installed on your machine, just run inside a virtualenv or with sudo:



                                                pip install rows


                                                If you're using Debian:



                                                sudo apt-get install rows


                                                Other Cool Features



                                                Converting Formats



                                                You can convert between any supported format:



                                                rows convert myfile.xlsx myfile.csv


                                                Querying



                                                Yes, you can use SQL into a CSV file:



                                                $ rows query 'SELECT city, area FROM table1 WHERE inhabitants > 100000' myfile.csv
                                                +----------------+--------+
                                                | city | area |
                                                +----------------+--------+
                                                | Angra dos Reis | 825.09 |
                                                | Araruama | 638.02 |
                                                +----------------+--------+


                                                Converting the output of the query to a file instead of stdout is also possible using the --output parameter.



                                                As a Python Library



                                                You can you in your Python programs too:



                                                import rows
                                                table = rows.import_from_csv('myfile.csv')
                                                rows.export_to_txt(table, 'myfile.txt')
                                                # `myfile.txt` will have same content as `rows print` output


                                                Hope you enjoy it!






                                                share|improve this answer




























                                                  6












                                                  6








                                                  6







                                                  If you want to use the command-line (and do not create an entire program to do the job), you'd like to use rows, a project I'm working on: it's a command-line interface to tabular data but also a Python library to use in your programs. With the command-line interface you can pretty-print any data in CSV, XLS, XLSX, HTML or any other tabular format supported by the library with a simple command:



                                                  rows print myfile.csv


                                                  If myfile.csv is like this:



                                                  state,city,inhabitants,area
                                                  RJ,Angra dos Reis,169511,825.09
                                                  RJ,Aperibé,10213,94.64
                                                  RJ,Araruama,112008,638.02
                                                  RJ,Areal,11423,110.92
                                                  RJ,Armação dos Búzios,27560,70.28


                                                  Then rows will print the contents in a beautiful way, like this:



                                                  +-------+-------------------------------+-------------+---------+
                                                  | state | city | inhabitants | area |
                                                  +-------+-------------------------------+-------------+---------+
                                                  | RJ | Angra dos Reis | 169511 | 825.09 |
                                                  | RJ | Aperibé | 10213 | 94.64 |
                                                  | RJ | Araruama | 112008 | 638.02 |
                                                  | RJ | Areal | 11423 | 110.92 |
                                                  | RJ | Armação dos Búzios | 27560 | 70.28 |
                                                  +-------+-------------------------------+-------------+---------+


                                                  Installing



                                                  If you are a Python developer and already have pip installed on your machine, just run inside a virtualenv or with sudo:



                                                  pip install rows


                                                  If you're using Debian:



                                                  sudo apt-get install rows


                                                  Other Cool Features



                                                  Converting Formats



                                                  You can convert between any supported format:



                                                  rows convert myfile.xlsx myfile.csv


                                                  Querying



                                                  Yes, you can use SQL into a CSV file:



                                                  $ rows query 'SELECT city, area FROM table1 WHERE inhabitants > 100000' myfile.csv
                                                  +----------------+--------+
                                                  | city | area |
                                                  +----------------+--------+
                                                  | Angra dos Reis | 825.09 |
                                                  | Araruama | 638.02 |
                                                  +----------------+--------+


                                                  Converting the output of the query to a file instead of stdout is also possible using the --output parameter.



                                                  As a Python Library



                                                  You can you in your Python programs too:



                                                  import rows
                                                  table = rows.import_from_csv('myfile.csv')
                                                  rows.export_to_txt(table, 'myfile.txt')
                                                  # `myfile.txt` will have same content as `rows print` output


                                                  Hope you enjoy it!






                                                  share|improve this answer















                                                  If you want to use the command-line (and do not create an entire program to do the job), you'd like to use rows, a project I'm working on: it's a command-line interface to tabular data but also a Python library to use in your programs. With the command-line interface you can pretty-print any data in CSV, XLS, XLSX, HTML or any other tabular format supported by the library with a simple command:



                                                  rows print myfile.csv


                                                  If myfile.csv is like this:



                                                  state,city,inhabitants,area
                                                  RJ,Angra dos Reis,169511,825.09
                                                  RJ,Aperibé,10213,94.64
                                                  RJ,Araruama,112008,638.02
                                                  RJ,Areal,11423,110.92
                                                  RJ,Armação dos Búzios,27560,70.28


                                                  Then rows will print the contents in a beautiful way, like this:



                                                  +-------+-------------------------------+-------------+---------+
                                                  | state | city | inhabitants | area |
                                                  +-------+-------------------------------+-------------+---------+
                                                  | RJ | Angra dos Reis | 169511 | 825.09 |
                                                  | RJ | Aperibé | 10213 | 94.64 |
                                                  | RJ | Araruama | 112008 | 638.02 |
                                                  | RJ | Areal | 11423 | 110.92 |
                                                  | RJ | Armação dos Búzios | 27560 | 70.28 |
                                                  +-------+-------------------------------+-------------+---------+


                                                  Installing



                                                  If you are a Python developer and already have pip installed on your machine, just run inside a virtualenv or with sudo:



                                                  pip install rows


                                                  If you're using Debian:



                                                  sudo apt-get install rows


                                                  Other Cool Features



                                                  Converting Formats



                                                  You can convert between any supported format:



                                                  rows convert myfile.xlsx myfile.csv


                                                  Querying



                                                  Yes, you can use SQL into a CSV file:



                                                  $ rows query 'SELECT city, area FROM table1 WHERE inhabitants > 100000' myfile.csv
                                                  +----------------+--------+
                                                  | city | area |
                                                  +----------------+--------+
                                                  | Angra dos Reis | 825.09 |
                                                  | Araruama | 638.02 |
                                                  +----------------+--------+


                                                  Converting the output of the query to a file instead of stdout is also possible using the --output parameter.



                                                  As a Python Library



                                                  You can you in your Python programs too:



                                                  import rows
                                                  table = rows.import_from_csv('myfile.csv')
                                                  rows.export_to_txt(table, 'myfile.txt')
                                                  # `myfile.txt` will have same content as `rows print` output


                                                  Hope you enjoy it!







                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited Aug 5 '16 at 1:22

























                                                  answered Aug 5 '16 at 1:16









                                                  Álvaro JustenÁlvaro Justen

                                                  30635




                                                  30635























                                                      4














                                                      Or, you could try some awk magic.
                                                      Howewer, I'm not a good awk user and cannot confirm this would work properly, and how to do it.






                                                      share|improve this answer



















                                                      • 9





                                                        Here is one awk CSV Parser I used a while back.. It seems quite well thought out... lorance.freeshell.org/csv

                                                        – Peter.O
                                                        Feb 15 '11 at 14:11
















                                                      4














                                                      Or, you could try some awk magic.
                                                      Howewer, I'm not a good awk user and cannot confirm this would work properly, and how to do it.






                                                      share|improve this answer



















                                                      • 9





                                                        Here is one awk CSV Parser I used a while back.. It seems quite well thought out... lorance.freeshell.org/csv

                                                        – Peter.O
                                                        Feb 15 '11 at 14:11














                                                      4












                                                      4








                                                      4







                                                      Or, you could try some awk magic.
                                                      Howewer, I'm not a good awk user and cannot confirm this would work properly, and how to do it.






                                                      share|improve this answer













                                                      Or, you could try some awk magic.
                                                      Howewer, I'm not a good awk user and cannot confirm this would work properly, and how to do it.







                                                      share|improve this answer












                                                      share|improve this answer



                                                      share|improve this answer










                                                      answered Feb 15 '11 at 12:30









                                                      rvsrvs

                                                      1,3431012




                                                      1,3431012








                                                      • 9





                                                        Here is one awk CSV Parser I used a while back.. It seems quite well thought out... lorance.freeshell.org/csv

                                                        – Peter.O
                                                        Feb 15 '11 at 14:11














                                                      • 9





                                                        Here is one awk CSV Parser I used a while back.. It seems quite well thought out... lorance.freeshell.org/csv

                                                        – Peter.O
                                                        Feb 15 '11 at 14:11








                                                      9




                                                      9





                                                      Here is one awk CSV Parser I used a while back.. It seems quite well thought out... lorance.freeshell.org/csv

                                                      – Peter.O
                                                      Feb 15 '11 at 14:11





                                                      Here is one awk CSV Parser I used a while back.. It seems quite well thought out... lorance.freeshell.org/csv

                                                      – Peter.O
                                                      Feb 15 '11 at 14:11











                                                      3














                                                      Have a look also at GNU Recutils and crush-tools.



                                                      (via http://www.reddit.com/r/commandline/comments/mfcu9/anyone_using_gnu_recutils_is_it_outdatedsuperceded/)






                                                      share|improve this answer




























                                                        3














                                                        Have a look also at GNU Recutils and crush-tools.



                                                        (via http://www.reddit.com/r/commandline/comments/mfcu9/anyone_using_gnu_recutils_is_it_outdatedsuperceded/)






                                                        share|improve this answer


























                                                          3












                                                          3








                                                          3







                                                          Have a look also at GNU Recutils and crush-tools.



                                                          (via http://www.reddit.com/r/commandline/comments/mfcu9/anyone_using_gnu_recutils_is_it_outdatedsuperceded/)






                                                          share|improve this answer













                                                          Have a look also at GNU Recutils and crush-tools.



                                                          (via http://www.reddit.com/r/commandline/comments/mfcu9/anyone_using_gnu_recutils_is_it_outdatedsuperceded/)







                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered Nov 21 '11 at 15:42









                                                          imz -- Ivan Zakharyaschevimz -- Ivan Zakharyaschev

                                                          6,42894192




                                                          6,42894192























                                                              3














                                                              Miller is another nice tool for manipulating name-based data, including CSV (with headers). To extract the first column of a CSV file, without caring about its name, you’d do something like



                                                              printf '"first,column",second,thirdn1,2,3n' |
                                                              mlr --csv --implicit-csv-header --headerless-csv-output cut -f 1





                                                              share|improve this answer


























                                                              • Miller is very impressive. I'd compare it to awk, but highly DSV-aware.

                                                                – Derek Mahar
                                                                Apr 18 '18 at 21:59
















                                                              3














                                                              Miller is another nice tool for manipulating name-based data, including CSV (with headers). To extract the first column of a CSV file, without caring about its name, you’d do something like



                                                              printf '"first,column",second,thirdn1,2,3n' |
                                                              mlr --csv --implicit-csv-header --headerless-csv-output cut -f 1





                                                              share|improve this answer


























                                                              • Miller is very impressive. I'd compare it to awk, but highly DSV-aware.

                                                                – Derek Mahar
                                                                Apr 18 '18 at 21:59














                                                              3












                                                              3








                                                              3







                                                              Miller is another nice tool for manipulating name-based data, including CSV (with headers). To extract the first column of a CSV file, without caring about its name, you’d do something like



                                                              printf '"first,column",second,thirdn1,2,3n' |
                                                              mlr --csv --implicit-csv-header --headerless-csv-output cut -f 1





                                                              share|improve this answer















                                                              Miller is another nice tool for manipulating name-based data, including CSV (with headers). To extract the first column of a CSV file, without caring about its name, you’d do something like



                                                              printf '"first,column",second,thirdn1,2,3n' |
                                                              mlr --csv --implicit-csv-header --headerless-csv-output cut -f 1






                                                              share|improve this answer














                                                              share|improve this answer



                                                              share|improve this answer








                                                              edited Sep 12 '17 at 11:58









                                                              Stéphane Chazelas

                                                              301k55565917




                                                              301k55565917










                                                              answered Sep 12 '17 at 11:33









                                                              Stephen KittStephen Kitt

                                                              167k24376454




                                                              167k24376454













                                                              • Miller is very impressive. I'd compare it to awk, but highly DSV-aware.

                                                                – Derek Mahar
                                                                Apr 18 '18 at 21:59



















                                                              • Miller is very impressive. I'd compare it to awk, but highly DSV-aware.

                                                                – Derek Mahar
                                                                Apr 18 '18 at 21:59

















                                                              Miller is very impressive. I'd compare it to awk, but highly DSV-aware.

                                                              – Derek Mahar
                                                              Apr 18 '18 at 21:59





                                                              Miller is very impressive. I'd compare it to awk, but highly DSV-aware.

                                                              – Derek Mahar
                                                              Apr 18 '18 at 21:59











                                                              2














                                                              To use python from the command line, you can check out pythonpy (https://github.com/Russell91/pythonpy):



                                                              $ echo $'a,b,cnd,e,f' | py '[x[1] for x in csv.reader(sys.stdin)']
                                                              b
                                                              e





                                                              share|improve this answer




























                                                                2














                                                                To use python from the command line, you can check out pythonpy (https://github.com/Russell91/pythonpy):



                                                                $ echo $'a,b,cnd,e,f' | py '[x[1] for x in csv.reader(sys.stdin)']
                                                                b
                                                                e





                                                                share|improve this answer


























                                                                  2












                                                                  2








                                                                  2







                                                                  To use python from the command line, you can check out pythonpy (https://github.com/Russell91/pythonpy):



                                                                  $ echo $'a,b,cnd,e,f' | py '[x[1] for x in csv.reader(sys.stdin)']
                                                                  b
                                                                  e





                                                                  share|improve this answer













                                                                  To use python from the command line, you can check out pythonpy (https://github.com/Russell91/pythonpy):



                                                                  $ echo $'a,b,cnd,e,f' | py '[x[1] for x in csv.reader(sys.stdin)']
                                                                  b
                                                                  e






                                                                  share|improve this answer












                                                                  share|improve this answer



                                                                  share|improve this answer










                                                                  answered Sep 27 '14 at 4:37









                                                                  RussellStewartRussellStewart

                                                                  1,11175




                                                                  1,11175























                                                                      2














                                                                      try "csvtool" this package
                                                                      it's handy command line tool for handling CSV files






                                                                      share|improve this answer



















                                                                      • 1





                                                                        Already mentioned, with more detail...

                                                                        – jasonwryan
                                                                        Sep 3 '15 at 9:27
















                                                                      2














                                                                      try "csvtool" this package
                                                                      it's handy command line tool for handling CSV files






                                                                      share|improve this answer



















                                                                      • 1





                                                                        Already mentioned, with more detail...

                                                                        – jasonwryan
                                                                        Sep 3 '15 at 9:27














                                                                      2












                                                                      2








                                                                      2







                                                                      try "csvtool" this package
                                                                      it's handy command line tool for handling CSV files






                                                                      share|improve this answer













                                                                      try "csvtool" this package
                                                                      it's handy command line tool for handling CSV files







                                                                      share|improve this answer












                                                                      share|improve this answer



                                                                      share|improve this answer










                                                                      answered Sep 3 '15 at 6:53









                                                                      dominicdominic

                                                                      211




                                                                      211








                                                                      • 1





                                                                        Already mentioned, with more detail...

                                                                        – jasonwryan
                                                                        Sep 3 '15 at 9:27














                                                                      • 1





                                                                        Already mentioned, with more detail...

                                                                        – jasonwryan
                                                                        Sep 3 '15 at 9:27








                                                                      1




                                                                      1





                                                                      Already mentioned, with more detail...

                                                                      – jasonwryan
                                                                      Sep 3 '15 at 9:27





                                                                      Already mentioned, with more detail...

                                                                      – jasonwryan
                                                                      Sep 3 '15 at 9:27











                                                                      2














                                                                      cissy will also do command-line csv processing. It's written in C (small/lightweight) with rpm and deb packages available for most distros.



                                                                      Using the example:



                                                                      echo '"this, is the first entry", this is the second, 34.5' | cissy -c 1
                                                                      "this, is the first entry"


                                                                      or



                                                                      echo '"this, is the first entry", this is the second, 34.5' | cissy -c 2
                                                                      this is the second


                                                                      or



                                                                      echo '"this, is the first entry", this is the second, 34.5' | cissy -c 2-
                                                                      this is the second, 34.5





                                                                      share|improve this answer






























                                                                        2














                                                                        cissy will also do command-line csv processing. It's written in C (small/lightweight) with rpm and deb packages available for most distros.



                                                                        Using the example:



                                                                        echo '"this, is the first entry", this is the second, 34.5' | cissy -c 1
                                                                        "this, is the first entry"


                                                                        or



                                                                        echo '"this, is the first entry", this is the second, 34.5' | cissy -c 2
                                                                        this is the second


                                                                        or



                                                                        echo '"this, is the first entry", this is the second, 34.5' | cissy -c 2-
                                                                        this is the second, 34.5





                                                                        share|improve this answer




























                                                                          2












                                                                          2








                                                                          2







                                                                          cissy will also do command-line csv processing. It's written in C (small/lightweight) with rpm and deb packages available for most distros.



                                                                          Using the example:



                                                                          echo '"this, is the first entry", this is the second, 34.5' | cissy -c 1
                                                                          "this, is the first entry"


                                                                          or



                                                                          echo '"this, is the first entry", this is the second, 34.5' | cissy -c 2
                                                                          this is the second


                                                                          or



                                                                          echo '"this, is the first entry", this is the second, 34.5' | cissy -c 2-
                                                                          this is the second, 34.5





                                                                          share|improve this answer















                                                                          cissy will also do command-line csv processing. It's written in C (small/lightweight) with rpm and deb packages available for most distros.



                                                                          Using the example:



                                                                          echo '"this, is the first entry", this is the second, 34.5' | cissy -c 1
                                                                          "this, is the first entry"


                                                                          or



                                                                          echo '"this, is the first entry", this is the second, 34.5' | cissy -c 2
                                                                          this is the second


                                                                          or



                                                                          echo '"this, is the first entry", this is the second, 34.5' | cissy -c 2-
                                                                          this is the second, 34.5






                                                                          share|improve this answer














                                                                          share|improve this answer



                                                                          share|improve this answer








                                                                          edited Sep 23 '15 at 3:27









                                                                          slass100

                                                                          1032




                                                                          1032










                                                                          answered Sep 18 '15 at 13:22









                                                                          slass100slass100

                                                                          211




                                                                          211























                                                                              1














                                                                              There is also a Curry library for reading/writing files in CSV format: CSV.






                                                                              share|improve this answer



















                                                                              • 2





                                                                                Would you mind posting some sample code, like the Perl, Python and R answers? (Especially since Curry is not a common unix scripting language.)

                                                                                – Gilles
                                                                                Apr 20 '11 at 21:31











                                                                              • @Gilles: Yes, you are right, I should post some sample code to make the answer better. I'm going to do this in a while.

                                                                                – imz -- Ivan Zakharyaschev
                                                                                Apr 20 '11 at 21:36
















                                                                              1














                                                                              There is also a Curry library for reading/writing files in CSV format: CSV.






                                                                              share|improve this answer



















                                                                              • 2





                                                                                Would you mind posting some sample code, like the Perl, Python and R answers? (Especially since Curry is not a common unix scripting language.)

                                                                                – Gilles
                                                                                Apr 20 '11 at 21:31











                                                                              • @Gilles: Yes, you are right, I should post some sample code to make the answer better. I'm going to do this in a while.

                                                                                – imz -- Ivan Zakharyaschev
                                                                                Apr 20 '11 at 21:36














                                                                              1












                                                                              1








                                                                              1







                                                                              There is also a Curry library for reading/writing files in CSV format: CSV.






                                                                              share|improve this answer













                                                                              There is also a Curry library for reading/writing files in CSV format: CSV.







                                                                              share|improve this answer












                                                                              share|improve this answer



                                                                              share|improve this answer










                                                                              answered Apr 20 '11 at 21:26









                                                                              imz -- Ivan Zakharyaschevimz -- Ivan Zakharyaschev

                                                                              6,42894192




                                                                              6,42894192








                                                                              • 2





                                                                                Would you mind posting some sample code, like the Perl, Python and R answers? (Especially since Curry is not a common unix scripting language.)

                                                                                – Gilles
                                                                                Apr 20 '11 at 21:31











                                                                              • @Gilles: Yes, you are right, I should post some sample code to make the answer better. I'm going to do this in a while.

                                                                                – imz -- Ivan Zakharyaschev
                                                                                Apr 20 '11 at 21:36














                                                                              • 2





                                                                                Would you mind posting some sample code, like the Perl, Python and R answers? (Especially since Curry is not a common unix scripting language.)

                                                                                – Gilles
                                                                                Apr 20 '11 at 21:31











                                                                              • @Gilles: Yes, you are right, I should post some sample code to make the answer better. I'm going to do this in a while.

                                                                                – imz -- Ivan Zakharyaschev
                                                                                Apr 20 '11 at 21:36








                                                                              2




                                                                              2





                                                                              Would you mind posting some sample code, like the Perl, Python and R answers? (Especially since Curry is not a common unix scripting language.)

                                                                              – Gilles
                                                                              Apr 20 '11 at 21:31





                                                                              Would you mind posting some sample code, like the Perl, Python and R answers? (Especially since Curry is not a common unix scripting language.)

                                                                              – Gilles
                                                                              Apr 20 '11 at 21:31













                                                                              @Gilles: Yes, you are right, I should post some sample code to make the answer better. I'm going to do this in a while.

                                                                              – imz -- Ivan Zakharyaschev
                                                                              Apr 20 '11 at 21:36





                                                                              @Gilles: Yes, you are right, I should post some sample code to make the answer better. I'm going to do this in a while.

                                                                              – imz -- Ivan Zakharyaschev
                                                                              Apr 20 '11 at 21:36











                                                                              1














                                                                              The github repo Structured Text Tools has a useful list of relevant linux command line tools. In particular, the Delimiter Separated Values section lists several CSV capable tools that directly support the operations requested.






                                                                              share|improve this answer




























                                                                                1














                                                                                The github repo Structured Text Tools has a useful list of relevant linux command line tools. In particular, the Delimiter Separated Values section lists several CSV capable tools that directly support the operations requested.






                                                                                share|improve this answer


























                                                                                  1












                                                                                  1








                                                                                  1







                                                                                  The github repo Structured Text Tools has a useful list of relevant linux command line tools. In particular, the Delimiter Separated Values section lists several CSV capable tools that directly support the operations requested.






                                                                                  share|improve this answer













                                                                                  The github repo Structured Text Tools has a useful list of relevant linux command line tools. In particular, the Delimiter Separated Values section lists several CSV capable tools that directly support the operations requested.







                                                                                  share|improve this answer












                                                                                  share|improve this answer



                                                                                  share|improve this answer










                                                                                  answered Sep 12 '17 at 12:12









                                                                                  JonDegJonDeg

                                                                                  714




                                                                                  714























                                                                                      0














                                                                                      An awk solution



                                                                                      awk -vq='"' '
                                                                                      func csv2del(n) {
                                                                                      for(i=n; i<=c; i++)
                                                                                      {if(i%2 == 1) gsub(/,/, OFS, a[i])
                                                                                      else a[i] = (q a[i] q)
                                                                                      out = (out) ? out a[i] : a[i]}
                                                                                      return out}
                                                                                      {c=split($0, a, q); out=X;
                                                                                      if(a[1]) $0=csv2del(1)
                                                                                      else $0=csv2del(2)}1' OFS='|' file





                                                                                      share|improve this answer




























                                                                                        0














                                                                                        An awk solution



                                                                                        awk -vq='"' '
                                                                                        func csv2del(n) {
                                                                                        for(i=n; i<=c; i++)
                                                                                        {if(i%2 == 1) gsub(/,/, OFS, a[i])
                                                                                        else a[i] = (q a[i] q)
                                                                                        out = (out) ? out a[i] : a[i]}
                                                                                        return out}
                                                                                        {c=split($0, a, q); out=X;
                                                                                        if(a[1]) $0=csv2del(1)
                                                                                        else $0=csv2del(2)}1' OFS='|' file





                                                                                        share|improve this answer


























                                                                                          0












                                                                                          0








                                                                                          0







                                                                                          An awk solution



                                                                                          awk -vq='"' '
                                                                                          func csv2del(n) {
                                                                                          for(i=n; i<=c; i++)
                                                                                          {if(i%2 == 1) gsub(/,/, OFS, a[i])
                                                                                          else a[i] = (q a[i] q)
                                                                                          out = (out) ? out a[i] : a[i]}
                                                                                          return out}
                                                                                          {c=split($0, a, q); out=X;
                                                                                          if(a[1]) $0=csv2del(1)
                                                                                          else $0=csv2del(2)}1' OFS='|' file





                                                                                          share|improve this answer













                                                                                          An awk solution



                                                                                          awk -vq='"' '
                                                                                          func csv2del(n) {
                                                                                          for(i=n; i<=c; i++)
                                                                                          {if(i%2 == 1) gsub(/,/, OFS, a[i])
                                                                                          else a[i] = (q a[i] q)
                                                                                          out = (out) ? out a[i] : a[i]}
                                                                                          return out}
                                                                                          {c=split($0, a, q); out=X;
                                                                                          if(a[1]) $0=csv2del(1)
                                                                                          else $0=csv2del(2)}1' OFS='|' file






                                                                                          share|improve this answer












                                                                                          share|improve this answer



                                                                                          share|improve this answer










                                                                                          answered Aug 12 '14 at 5:23









                                                                                          SriniSrini

                                                                                          1613




                                                                                          1613























                                                                                              0














                                                                                              I'd recommend xsv - A fast CSV command line toolkit written in Rust (Github).



                                                                                              Written by Ripgrep's author.



                                                                                              Featured in How we made our CSV processing 142x faster (Reddit thread).






                                                                                              share|improve this answer




























                                                                                                0














                                                                                                I'd recommend xsv - A fast CSV command line toolkit written in Rust (Github).



                                                                                                Written by Ripgrep's author.



                                                                                                Featured in How we made our CSV processing 142x faster (Reddit thread).






                                                                                                share|improve this answer


























                                                                                                  0












                                                                                                  0








                                                                                                  0







                                                                                                  I'd recommend xsv - A fast CSV command line toolkit written in Rust (Github).



                                                                                                  Written by Ripgrep's author.



                                                                                                  Featured in How we made our CSV processing 142x faster (Reddit thread).






                                                                                                  share|improve this answer













                                                                                                  I'd recommend xsv - A fast CSV command line toolkit written in Rust (Github).



                                                                                                  Written by Ripgrep's author.



                                                                                                  Featured in How we made our CSV processing 142x faster (Reddit thread).







                                                                                                  share|improve this answer












                                                                                                  share|improve this answer



                                                                                                  share|improve this answer










                                                                                                  answered Aug 5 '18 at 19:24









                                                                                                  Nicolas GirardNicolas Girard

                                                                                                  1




                                                                                                  1























                                                                                                      0














                                                                                                      One of the best tool is Miller (http://johnkerl.org/miller/doc/index.html). It is like awk, sed, cut, join, and sort for name-indexed data such as CSV, TSV, and tabular JSON.



                                                                                                      In example



                                                                                                      echo '"this, is the first entry", this is the second, 34.5' | 
                                                                                                      mlr --icsv --implicit-csv-header cat


                                                                                                      gives you



                                                                                                      1=this, is the first entry,2= this is the second,3= 34.5


                                                                                                      If you want a TSV



                                                                                                      echo '"this, is the first entry", this is the second, 34.5' |
                                                                                                      mlr --c2t --implicit-csv-header cat



                                                                                                      gives you (it's possible to remove the header)



                                                                                                      1       2       3
                                                                                                      this, is the first entry this is the second 34.5


                                                                                                      If you want first and third column, changing their order



                                                                                                      echo '"this, is the first entry", this is the second, 34.5' | 
                                                                                                      mlr --csv --implicit-csv-header --headerless-csv-output cut -o -f 3,1


                                                                                                      gives you



                                                                                                       34.5,"this, is the first entry"




                                                                                                      share




























                                                                                                        0














                                                                                                        One of the best tool is Miller (http://johnkerl.org/miller/doc/index.html). It is like awk, sed, cut, join, and sort for name-indexed data such as CSV, TSV, and tabular JSON.



                                                                                                        In example



                                                                                                        echo '"this, is the first entry", this is the second, 34.5' | 
                                                                                                        mlr --icsv --implicit-csv-header cat


                                                                                                        gives you



                                                                                                        1=this, is the first entry,2= this is the second,3= 34.5


                                                                                                        If you want a TSV



                                                                                                        echo '"this, is the first entry", this is the second, 34.5' |
                                                                                                        mlr --c2t --implicit-csv-header cat



                                                                                                        gives you (it's possible to remove the header)



                                                                                                        1       2       3
                                                                                                        this, is the first entry this is the second 34.5


                                                                                                        If you want first and third column, changing their order



                                                                                                        echo '"this, is the first entry", this is the second, 34.5' | 
                                                                                                        mlr --csv --implicit-csv-header --headerless-csv-output cut -o -f 3,1


                                                                                                        gives you



                                                                                                         34.5,"this, is the first entry"




                                                                                                        share


























                                                                                                          0












                                                                                                          0








                                                                                                          0







                                                                                                          One of the best tool is Miller (http://johnkerl.org/miller/doc/index.html). It is like awk, sed, cut, join, and sort for name-indexed data such as CSV, TSV, and tabular JSON.



                                                                                                          In example



                                                                                                          echo '"this, is the first entry", this is the second, 34.5' | 
                                                                                                          mlr --icsv --implicit-csv-header cat


                                                                                                          gives you



                                                                                                          1=this, is the first entry,2= this is the second,3= 34.5


                                                                                                          If you want a TSV



                                                                                                          echo '"this, is the first entry", this is the second, 34.5' |
                                                                                                          mlr --c2t --implicit-csv-header cat



                                                                                                          gives you (it's possible to remove the header)



                                                                                                          1       2       3
                                                                                                          this, is the first entry this is the second 34.5


                                                                                                          If you want first and third column, changing their order



                                                                                                          echo '"this, is the first entry", this is the second, 34.5' | 
                                                                                                          mlr --csv --implicit-csv-header --headerless-csv-output cut -o -f 3,1


                                                                                                          gives you



                                                                                                           34.5,"this, is the first entry"




                                                                                                          share













                                                                                                          One of the best tool is Miller (http://johnkerl.org/miller/doc/index.html). It is like awk, sed, cut, join, and sort for name-indexed data such as CSV, TSV, and tabular JSON.



                                                                                                          In example



                                                                                                          echo '"this, is the first entry", this is the second, 34.5' | 
                                                                                                          mlr --icsv --implicit-csv-header cat


                                                                                                          gives you



                                                                                                          1=this, is the first entry,2= this is the second,3= 34.5


                                                                                                          If you want a TSV



                                                                                                          echo '"this, is the first entry", this is the second, 34.5' |
                                                                                                          mlr --c2t --implicit-csv-header cat



                                                                                                          gives you (it's possible to remove the header)



                                                                                                          1       2       3
                                                                                                          this, is the first entry this is the second 34.5


                                                                                                          If you want first and third column, changing their order



                                                                                                          echo '"this, is the first entry", this is the second, 34.5' | 
                                                                                                          mlr --csv --implicit-csv-header --headerless-csv-output cut -o -f 3,1


                                                                                                          gives you



                                                                                                           34.5,"this, is the first entry"





                                                                                                          share











                                                                                                          share


                                                                                                          share










                                                                                                          answered 4 mins ago









                                                                                                          aborrusoaborruso

                                                                                                          20619




                                                                                                          20619






























                                                                                                              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%2f7425%2fis-there-a-robust-command-line-tool-for-processing-csv-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

                                                                                                              Accessing regular linux commands in Huawei's Dopra Linux

                                                                                                              Can't connect RFCOMM socket: Host is down

                                                                                                              Kernel panic - not syncing: Fatal Exception in Interrupt