hot string

K

kkbyte

Hi all,
I have this problem ...
I have a file with only long string separated by " | " for
example ...

|accrued=0|fee=0|commission=0|change_in_volume=0|
change_in_invested=4494367|change_in_accrued=0|

and I want to've another file so

accrued=0
fee=0
commission=0
change_in_volume=0
change_in_invested=4494367
change_in_accrued=0

Help me!
Tks
 
M

Mirco Wahab

kkbyte said:
I have a file with only long string separated by " | " for
example ...

|accrued=0|fee=0|commission=0|change_in_volume=0|
change_in_invested=4494367|change_in_accrued=0|

and I want to've another file so

accrued=0
fee=0
commission=0
change_in_volume=0
change_in_invested=4494367
change_in_accrued=0

Please post some Perl code where you tried that already.

You mean, you have a string like:

my $fromfile = '|accrued=0|fee=0|commission=0|change_in_volume=0'
. '|change_in_invested=4494367|change_in_accrued=0|';

and you need to get the 'fields' between |...|?

You should apply a simple split

my @contents = split /\|/, $fromfile;

after which you may print the extracted contents
in the desired way:

print join "\n", @contents;

To suppress empty lines (coming from empty fields), write:

print join "\n", grep length, @contents;


Regards

M.
 
T

Tad McClellan

I have a file with only long string separated by " | " for
example ...

|accrued=0|fee=0|commission=0|change_in_volume=0|
change_in_invested=4494367|change_in_accrued=0|

and I want to've another file so

accrued=0
fee=0
commission=0
change_in_volume=0
change_in_invested=4494367
change_in_accrued=0


perl -pe 'tr/|/\n/' a_file >another_file
 

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
474,291
Messages
2,571,483
Members
48,142
Latest member
MarkBurbac

Latest Threads

Top