0

I have a file in csv format. I know positions where I want to chip off a chunk from the file and write it as a new csv file.

split command splits a file into equal-sized chunks. I wonder if there exists an effective (the file is huge) way to split file into chunks of different sizes?

Sergey Ivanov
  • 3,719
  • 7
  • 34
  • 59
  • You might want to look at this [link](http://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash) – hrv Sep 28 '13 at 21:40

1 Answers1

1

I assume you want to split the file at a newline character. If this is the case you can use the head and tail commands to grab a number of lines from the beginning and from the end of your file, respectively.

If you want to copy a new of lines from within the file you can use sed, e.g.

sed -e 1,Nd -e Mq file

where N should be replaced with the line number of the line preceding the first line to display and M should be the line number of the last line to display.

Adam Zalcman
  • 26,643
  • 4
  • 71
  • 92
  • So, last command is helpful. But how do I write these lines to a new file? – Sergey Ivanov Sep 28 '13 at 22:10
  • Just [redirect](http://www.tldp.org/LDP/abs/html/io-redirection.html) it to a file which doesn't exist in the current directory, e.g. `sed -e 1,10d -e 20q big.csv > small.csv` – Adam Zalcman Sep 28 '13 at 23:20