Advertisement
Guest User

Untitled

a guest
Oct 31st, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.73 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # check if an input filename was passed as a command
  4. # line argument:
  5. if [ ! $# == 1 ]; then
  6.   echo "Please specify the name of a file to split!"
  7.   exit
  8. fi
  9.  
  10. # create a directory to store the output:
  11. mkdir output
  12.  
  13. # create a temporary file containing the header without
  14. # the content:
  15. head -n 1 $1 > header.csv
  16.  
  17. # create a temporary file containing the content without
  18. # the header:
  19. tail +2 $1 > content.csv
  20.  
  21. # split the content file into multiple files of 5 lines each:
  22. split -l 5 content.csv output/data_
  23.  
  24. # loop through the new split files, adding the header
  25. # and a '.csv' extension:
  26. for f in output/*; do cat header.csv $f > $f.csv; rm $f; done;
  27.  
  28. # remove the temporary files:
  29. rm header.csv
  30. rm content.csv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement