Skip to content

Instantly share code, notes, and snippets.

@metric-space
Last active January 8, 2021 05:36
Show Gist options
  • Save metric-space/9e7ce85a1161095d07f2a7dd85ba2273 to your computer and use it in GitHub Desktop.
Save metric-space/9e7ce85a1161095d07f2a7dd85ba2273 to your computer and use it in GitHub Desktop.

Revisions

  1. Luke Meyers revised this gist Jan 8, 2021. No changes.
  2. Luke Meyers created this gist Jan 8, 2021.
    25 changes: 25 additions & 0 deletions cut.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    inputfile=$1

    filename="${inputfile%.*}"

    line_count=$(wc -l < $1)

    row_count=$((${line_count} - 1))

    movement=$(($row_count/$2))

    i=0
    j=1

    while [ $j -lt $row_count ]
    do
    # echo $(($j + 1))
    # echo $(($j + $movement))
    t="${filename}-${i}.csv"
    touch $t
    head -n 1 $1 > $t
    cat $1 | sed -n "$(($j + 1)),$(($j + $movement ))p" >> $t
    j=$[$j + movement]
    i=$[$i+1]
    done