Split single file into multiple files based on patterns

Alain Ketterlin alain at dpt-info.u-strasbg.fr
Wed Oct 24 01:46:28 EDT 2012


satyam <dirac.sat at gmail.com> writes:

> I have a text file like this
>
> A1980JE39300007 2732 4195 12.527000
> A1980JE39300007 3465 9720 22.000000
> A1980JE39300007 2732 9720 18.000000
> A1980KK18700010 130 303 4.985000
> A1980KK18700010 7 4915 0.435000
[...]
> I want to split the file and get multiple files like
> A1980JE39300007.txt and A1980KK18700010.txt, where each file will
> contain column2, 3 and 4.

Sorry for being completely off-topic here, but awk has a very convenient
feature to deal with this. Simply use:

    awk '{ print $2,$3,$4 > $1".txt"; }' /path/to/your/file

-- Alain.



More information about the Python-list mailing list