Veeraraju_Mareddi wrote:
> I have a large data file which has ; as delimiter and i want
> this to be replaced newline character ,but unfortunately my
> script is not working
>
> my code is given below
> ####################################################
> open(NOTE ,">>c:\\data.txt"); #data file
Here you open the filehandle NOTE to append to a file.
> while (<NOTE>)
And here you try to read from the filehandle, even though it was opened only
for appending. That doesn't make sense.
> {
> s/;/"\n"/;
> }
And here you replace semicolons with quote-newline-quote. The replacement
part of an s/// expression interpolates like a double-quoted string, so \n
alone is sufficient.
However, after changing the string, you do not write it to a file.
> close(NOTE);
> #######################################################
>
> It doesn't report any error task is not being performed
>
> Please help me.
Does your file have newlines already? Otherwise, <FILE> will read in the
whole file in one chunk, which may not be what you want.
* If your file contains semicolons and newlines and you want to change the
semicolons to also be newlines, I suggest
perl -i.bak -wpe "tr/;/\n/" filename.txt
Read up `perldoc perlrun` for information on the -i flag (in-place editing)
and the -p flag.
* If your file contains data separated by semicolons but no newlines, I
suggest splitting on semicolons:
perl -i.bak -l -073 -wpe1 filename.txt
This sets $\, the output record separator, to "\n", and $/, the input record
separator, to "\073", which is the semicolon, and ensure that each record
gets chomped. That means that each record read will end with a semicolon,
which gets chomped on reading, and gets a newline added on printing (which
is done automatically as a result of the -p switch). The -e1 is a dummy
script which is equivalent to a program of
1;
and does nothing (besides processing each line due to the -p -l -0 -i
switches).
Note also that in any case, the newlines will actually be \x0d\x0a on the
disk due to Win32 text mode IO processing.
Hope this helps.
Cheers,
Philip
--
Philip Newton <[EMAIL PROTECTED]>
All opinions are my own, not my employer's.
If you're not part of the solution, you're part of the precipitate.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]