I have a data file, which can have N rows, and each row is composed M elements separated by white space. Currently, I want to separate each row into several segments. In other words, assume the number of segments is 3; then the original file will be separated into 3 files, each of which has N rows and each row has M/3 elements. Besides writing C++ or Java program, Is there any efficient approach that can fulfill this task on Unix/Linux?
|
This caters for a varying number of fields in the same file, and the last segment being only partialy filled, ie less fields than specified (per segment).
|
||||
|
|
|
Is this what you are looking for?
Or did you want something more general?
Note: this relies on the assumption that all rows have the same number of columns. |
||||
|
|
|
If your file is clean, I would advice to use the standard application
You can choose to either use the combination -d -f, or -c If your file is not TAB delimited, but nicely delimited by space, you can do
to select the first three columns. If you want to select the 4th column, that is in between character 25 and 36, you can do
|
|||
|
|
|
sep_file.ksh
Usage: |
||||
|
|
