CSV SQL Statements

CSV SQL Statements #

To process local CSV files use q #

Install q

Examples

  • Run query against a CSV with header row and comma delimiter

    q "select `Email Address` from export_*.csv limit 2" -H -d ,
    
  • Header row, comma delimiter, and include header row in output

    q "select distinct `Email Address` from exoirt_*.csv limit 2" -H -d , -O
    
    • -H stands for headers in input
    • -d , stands for delimiter to comma
    • -O include header row in output
  • Order by 1st column

    q "select distinct `Email Address` from exoirt_*.csv order by 1" -H -d , -O
    
  • Save results to CSV file

    q "select distinct `Email Address` from export_*.csv order by 1" -H -d , -O > out.csv
    
  • Join 2 local CSV files

    q "select email from export1.csv where email not in ⮠ 
       (select  `Email Address` from export2_*.csv)" -H -d , -O > out.csv