Split single file into multiple files based on patterns

Mark Lawrence breamoreboy at yahoo.co.uk
Wed Oct 24 02:13:24 EDT 2012


On 24/10/2012 06:46, Alain Ketterlin wrote:
> 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.
>

Although practicality beats purity :)

-- 
Cheers.

Mark Lawrence.




More information about the Python-list mailing list