# splitting a pipe delimited file in unix

**URL:** <https://community.unix.com/t/splitting-a-pipe-delimited-file-in-unix/169883>\
**Category:** Shell Programming and Scripting\
**Created:** [March 19, 2007, 11:51pm UTC](https://community.unix.com/t/splitting-a-pipe-delimited-file-in-unix/169883 "2007-03-19T23:51:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddedic](https://community.unix.com/letter_avatar/ddedic/32/5_5575768a8748004e209b776fc1b2916d.png) [@ddedic](https://community.unix.com/u/ddedic)\
**Post date:** [March 19, 2007, 11:51pm UTC](https://community.unix.com/t/splitting-a-pipe-delimited-file-in-unix/169883/1 "2007-03-19T23:51:01Z")

</div>

Could one of you shad some light on this:

I need to split the file by determining the record count and than splitting it up into 4 files. Please note, this is not a fixed record length but rather a "|" delimited file.

I am not sure as how to handle reminder/offset for the 4th file.  
For example:

"$1|wc -l" /4 + reminder

Please let me know. :rolleyes:

---

<div class="post-metadata">

**Author:** ![matrixmadhan](https://community.unix.com/letter_avatar/matrixmadhan/32/5_5575768a8748004e209b776fc1b2916d.png) [@matrixmadhan](https://community.unix.com/u/matrixmadhan)\
**Post date:** [March 20, 2007, 12:41am UTC](https://community.unix.com/t/splitting-a-pipe-delimited-file-in-unix/169883/2 "2007-03-20T00:41:54Z")

</div>

looking for split command

if not

please post sample input and output 🙂

---

<div class="post-metadata">

**Author:** ![ddedic](https://community.unix.com/letter_avatar/ddedic/32/5_5575768a8748004e209b776fc1b2916d.png) [@ddedic](https://community.unix.com/u/ddedic)\
**Post date:** [March 20, 2007, 12:48am UTC](https://community.unix.com/t/splitting-a-pipe-delimited-file-in-unix/169883/3 "2007-03-20T00:48:54Z")

</div>

My file for ex. is a 10mil record file. Within the shell script I need to determine the record count and divided it into 4 separate files.

Is it ok to do a wc -l into a variable / 4? Would reminder take care of itself - meaning it will be a part of the 4th file.

Please advise and I hope this helps.

---

<div class="post-metadata">

**Author:** ![matrixmadhan](https://community.unix.com/letter_avatar/matrixmadhan/32/5_5575768a8748004e209b776fc1b2916d.png) [@matrixmadhan](https://community.unix.com/u/matrixmadhan)\
**Post date:** [March 20, 2007, 1:09am UTC](https://community.unix.com/t/splitting-a-pipe-delimited-file-in-unix/169883/4 "2007-03-20T01:09:22Z")

</div>

```nohighlight
split -l $(( $( wc -l < filename ) / 4)) filename

```

---

<div class="post-metadata">

**Author:** ![ddedic](https://community.unix.com/letter_avatar/ddedic/32/5_5575768a8748004e209b776fc1b2916d.png) [@ddedic](https://community.unix.com/u/ddedic)\
**Post date:** [March 20, 2007, 1:16am UTC](https://community.unix.com/t/splitting-a-pipe-delimited-file-in-unix/169883/5 "2007-03-20T01:16:57Z")

</div>

thank you matrixmadhan. I will try this one first thing tomorrow morning.

Thank you again.
