split file

B

Babu

Hi,

I am new to perl.I have basic question about splitting a file into 2.

the input file= temp.hex

contents

4A
5F
C3
3D

is there a one liner to split this file into 2 files temp1.hex
containing

4A
5F


and temp2.hex having

C3
3D


Thanks in advance

SN
 
J

Jürgen Exner

I am new to perl.I have basic question about splitting a file into 2.

the input file= temp.hex

contents

4A
5F
C3
3D

is there a one liner to split this file into 2 files temp1.hex
containing

4A
5F


and temp2.hex having

C3
3D

Probably there is. But unless you tell us the criteria for _where_ to split
it's everyone's guess as what the algorithm is supposed to do.
- split after a given value 5F?
- split before a given value C3?
- split after 2 lines?
- split between given values 5F and C3?
- split one line after a given value 4A?
- ....

In any case, did you check the standard program split? Maybe it already does
what you are looking for.

jue
 
J

John W. Krahn

Babu said:
I am new to perl.I have basic question about splitting a file into 2.

the input file= temp.hex

contents

4A
5F
C3
3D

is there a one liner to split this file into 2 files temp1.hex
containing

4A
5F


and temp2.hex having

C3
3D

perl -e'$h = ( @x = <> ) / 2 + .5; open _ and print _ splice @x, 0, $h
for map ">$_", qw/temp1.hex temp2.hex/'



John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top