Skip to content

Instantly share code, notes, and snippets.

@lshapz
Last active March 12, 2018 17:29
Show Gist options
  • Save lshapz/1ab5d5a954de7246fae61477bb0aef43 to your computer and use it in GitHub Desktop.
Save lshapz/1ab5d5a954de7246fae61477bb0aef43 to your computer and use it in GitHub Desktop.

Revisions

  1. lshapz revised this gist Mar 12, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion header_row_how_to.md
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ tail -n +2 orig.csv > headless.csv
    * convert csv file into a json file

    ```
    csvtojson useful.csv > converted.json
    csvtojson final.csv > converted.json
    ```

    ##### Tools:
  2. lshapz revised this gist Feb 7, 2018. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions header_row_how_to.md
    Original file line number Diff line number Diff line change
    @@ -25,8 +25,7 @@ tail -n +2 orig.csv > headless.csv
    * insert the new header row into the csv file

    ```
    ( echo "headers","as","comma","delimited","strings" ; cat headless.csv ) >
    final.csv && rm headless.csv
    ( echo "headers","as","comma","delimited","strings" ; cat headless.csv ) > final.csv && rm headless.csv
    ```

    * convert csv file into a json file
  3. lshapz revised this gist Feb 7, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions header_row_how_to.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    #####Problem:
    ##### Problem:

    * 100000 line CSV file.
    * header row includes unnecessary type definitions in it (i.e. "header1:String,header2:Decimal,header3:INT32")
    * CSV is too large to open in Numbers/Google Sheets for simple find/replace

    #####Solution:
    ##### Solution:

    * get only the header row

    @@ -35,7 +35,7 @@ final.csv && rm headless.csv
    csvtojson useful.csv > converted.json
    ```

    #####Tools:
    ##### Tools:

    * bash (MacOS command line/terminal)

  4. lshapz revised this gist Feb 7, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions header_row_how_to.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    Problem:
    #####Problem:

    * 100000 line CSV file.
    * header row includes unnecessary type definitions in it (i.e. "header1:String,header2:Decimal,header3:INT32")
    * CSV is too large to open in Numbers/Google Sheets for simple find/replace

    Solution:
    #####Solution:

    * get only the header row

    @@ -35,7 +35,7 @@ final.csv && rm headless.csv
    csvtojson useful.csv > converted.json
    ```

    Tools:
    #####Tools:

    * bash (MacOS command line/terminal)

  5. lshapz created this gist Feb 7, 2018.
    44 changes: 44 additions & 0 deletions header_row_how_to.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    Problem:

    * 100000 line CSV file.
    * header row includes unnecessary type definitions in it (i.e. "header1:String,header2:Decimal,header3:INT32")
    * CSV is too large to open in Numbers/Google Sheets for simple find/replace

    Solution:

    * get only the header row

    ```
    head -n 1 orig.csv > headers.csv
    ```

    * open headers.csv, use find and replace to delte all the ":String" cruft

    * copy the revised row into a text editor, put quotation marks around all the strings, copy again

    * get everything but the header row

    ```
    tail -n +2 orig.csv > headless.csv
    ```

    * insert the new header row into the csv file

    ```
    ( echo "headers","as","comma","delimited","strings" ; cat headless.csv ) >
    final.csv && rm headless.csv
    ```

    * convert csv file into a json file

    ```
    csvtojson useful.csv > converted.json
    ```

    Tools:

    * bash (MacOS command line/terminal)

    * a spreadsheet app (MacOS Numbers.app)

    * [csvtojson](https://github.com/Keyang/node-csvtojson) npm package