Split positional flat file.

Hi,

I need to split positional flat file, based on value at position 43-45.( in red "410")
Example:
12345678907886421689 200920184820410200920020092002007
12345678907886421689 200920184820411200920020092002007
12345678907886421689 200920184820411200920020092002007
12345678907886421684 200924184820410200920020092002007
12345678907886421684 200924184820411200920020092002007
12345678907886421684 200924184820411200920020092002007

I tried using read line but it reduces the space and so positions get changed.

Is there any other way of doing this.

Please advice.

Thanks.

---------- Post updated at 03:35 AM ---------- Previous update was at 03:31 AM ----------

Hi,

I need to split positional flat file, based on value at position 43-45.( in red "410")
Example:
12345678907886421689 200920184820410200920020092002007
12345678907886421689 200920184820411200920020092002007
12345678907886421689 200920184820411200920020092002007
12345678907886421684 200924184820410200920020092002007
12345678907886421684 200924184820411200920020092002007
12345678907886421684 200924184820411200920020092002007

I tried using read line but it reduces the space and so positions get changed.

Is there any other way of doing this.

Please advice.

Thanks.

Yes ,

It is possible. Can You post the output your expecting ?..

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

can you post what you have tried too???

For every "410" at position 43 to 45, I need to create new file.

for sample data shown in above post, I need 2 output files

 
First file will have following lines 
 
12345678907886421689 200920184820410200920020092002007
12345678907886421689 200920184820411200920020092002007
12345678907886421689 200920184820411200920020092002007
 
and Second will have following lines
 
12345678907886421684 200924184820410200920020092002007
12345678907886421684 200924184820411200920020092002007
12345678907886421684 200924184820411200920020092002007
 

An awk will do the work :

awk ' BEGIN { c=0 }
{
if(substr($0,34,3)=="410")
{
c++;
print >> "File_" c ; next ;
}
else
{
print >> "File_" c;
}
}'  input_file.txt

according to the Data you posted Position of "410" is at 34-36.

Thanks panyam. This is working. Thanks alot.