Skip to content

Instantly share code, notes, and snippets.

@ptux
Forked from songthamtung/split_csv.sh
Created December 20, 2020 05:52
Show Gist options
  • Save ptux/2c8bc65d75d20096e509be7cdb2f9eed to your computer and use it in GitHub Desktop.
Save ptux/2c8bc65d75d20096e509be7cdb2f9eed to your computer and use it in GitHub Desktop.

Revisions

  1. @songthamtung songthamtung revised this gist Dec 11, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion split_csv.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #!/bin/bash
    FILENAME=file.csv
    FILENAME=guid.csv
    HDR=$(head -1 $FILENAME)
    split -l 1000 $FILENAME xyz
    n=1
  2. @songthamtung songthamtung created this gist Dec 11, 2020.
    14 changes: 14 additions & 0 deletions split_csv.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    #!/bin/bash
    FILENAME=file.csv
    HDR=$(head -1 $FILENAME)
    split -l 1000 $FILENAME xyz
    n=1
    for f in xyz*
    do
    if [ $n -gt 1 ]; then
    echo $HDR > Part${n}-$FILENAME
    fi
    cat $f >> Part${n}-$FILENAME
    rm $f
    ((n++))
    done