Skip to main content
typo fix
Source Link
peterph
  • 31.5k
  • 3
  • 74
  • 76

Have a look at the command line utility named cut. It can extract columns if they are separated by a unique delimiter. To recombine the parts you can use paste.

If you have, for example a typical comma-separated format

$ cat debts.csv
Name,Age,Debt
Alice,20,1337
Bob,30,42

$ cat pets.csv
Name,Pet
Alice,Dog
Bob,Cat

you could extract names and debts with

$ cut -d, -f1,3 debts.csv
Name,Debt
Alice,1337
Bob,42

and combine debts with pets using

$ cut -d, -f2 pets.csv | paste -d, debts.csv -
Name,Age,Debt,PatPet
Alice,20,1337,Dog
Bob,30,42,Cat
  • With cut and paste, -d determines the delimiter for the fields,
  • -f selects the columns to extract for cut and
  • - directs to use the standard input (i.e. in the latter paste case, from the pipe) instead of a file.

Have a look at the command line utility named cut. It can extract columns if they are separated by a unique delimiter. To recombine the parts you can use paste.

If you have, for example a typical comma-separated format

$ cat debts.csv
Name,Age,Debt
Alice,20,1337
Bob,30,42

$ cat pets.csv
Name,Pet
Alice,Dog
Bob,Cat

you could extract names and debts with

$ cut -d, -f1,3 debts.csv
Name,Debt
Alice,1337
Bob,42

and combine debts with pets using

$ cut -d, -f2 pets.csv | paste -d, debts.csv -
Name,Age,Debt,Pat
Alice,20,1337,Dog
Bob,30,42,Cat
  • With cut and paste, -d determines the delimiter for the fields,
  • -f selects the columns to extract for cut and
  • - directs to use the standard input (i.e. in the latter paste case, from the pipe) instead of a file.

Have a look at the command line utility named cut. It can extract columns if they are separated by a unique delimiter. To recombine the parts you can use paste.

If you have, for example a typical comma-separated format

$ cat debts.csv
Name,Age,Debt
Alice,20,1337
Bob,30,42

$ cat pets.csv
Name,Pet
Alice,Dog
Bob,Cat

you could extract names and debts with

$ cut -d, -f1,3 debts.csv
Name,Debt
Alice,1337
Bob,42

and combine debts with pets using

$ cut -d, -f2 pets.csv | paste -d, debts.csv -
Name,Age,Debt,Pet
Alice,20,1337,Dog
Bob,30,42,Cat
  • With cut and paste, -d determines the delimiter for the fields,
  • -f selects the columns to extract for cut and
  • - directs to use the standard input (i.e. in the latter paste case, from the pipe) instead of a file.
added 628 characters in body
Source Link
XZS
  • 1.5k
  • 15
  • 27

Have a look at the command line utility named cutcut. It can extract columns if they are separated by a unique delimiter. To recombine the parts you can use paste.

If you have, for example a typical comma-separated format

$ cat debts.csv
Name,Age,Debt
Alice,20,1337
Bob,30,42

$ cat pets.csv
Name,Pet
Alice,Dog
Bob,Cat

you could extract names and debts with

$ cut -d, -f1,3 debts.csv
Name,Debt
Alice,1337
Bob,42

and combine debts with pets using

$ cut -d, -f2 pets.csv | paste -d, debts.csv -
Name,Age,Debt,Pat
Alice,20,1337,Dog
Bob,30,42,Cat
  • With cut and paste, -d determines the delimiter for the fields,
  • -f selects the columns to extract for cut and
  • - directs to use the standard input (i.e. in the latter paste case, from the pipe) instead of a file.

Have a look at the command line utility named cut. It can extract columns if they are separated by a unique delimiter. If you have, for example a typical comma-separated format

Name,Age,Debt
Alice,20,1337
Bob,30,42

you could extract names and debts with

cut -d, -f1,3 debts.csv

Have a look at the command line utility named cut. It can extract columns if they are separated by a unique delimiter. To recombine the parts you can use paste.

If you have, for example a typical comma-separated format

$ cat debts.csv
Name,Age,Debt
Alice,20,1337
Bob,30,42

$ cat pets.csv
Name,Pet
Alice,Dog
Bob,Cat

you could extract names and debts with

$ cut -d, -f1,3 debts.csv
Name,Debt
Alice,1337
Bob,42

and combine debts with pets using

$ cut -d, -f2 pets.csv | paste -d, debts.csv -
Name,Age,Debt,Pat
Alice,20,1337,Dog
Bob,30,42,Cat
  • With cut and paste, -d determines the delimiter for the fields,
  • -f selects the columns to extract for cut and
  • - directs to use the standard input (i.e. in the latter paste case, from the pipe) instead of a file.
Source Link
XZS
  • 1.5k
  • 15
  • 27

Have a look at the command line utility named cut. It can extract columns if they are separated by a unique delimiter. If you have, for example a typical comma-separated format

Name,Age,Debt
Alice,20,1337
Bob,30,42

you could extract names and debts with

cut -d, -f1,3 debts.csv