Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

adding a crlf

Thread view: 
tmw - 28 Feb 2008 19:09 GMT
Trying to format a file by adding a crlf at every Nth position in a
file.  Not sure what is the best way to do this and looking for ideas
of how to do it.  I am currently running a process in ANT to handle
the file and was hoping that I could achieve this by using an already
existing ANT task ( replace?, replaceregexp?)

example of data in file:
some text in file that goes like this and keeps going with no returns
in it but i want to add some to reformat the file.

what i would want the output to be after processing - by adding a
crlf  after every 10th character in the file:
some text
in file t
hat goes l
ike this a
nd keeps g
oing with
no return
s in it bu
t i want t
o add some
to reform
at the fil
e.

=====================
thanks
tmw
Daniele Futtorovic - 28 Feb 2008 21:23 GMT
> Trying to format a file by adding a crlf at every Nth position in a
> file.  Not sure what is the best way to do this and looking for ideas
[quoted text clipped - 25 lines]
> thanks
> tmw

If awk is an option, I'd go for that.

Signature

DF.

Stanimir Stamenkov - 28 Feb 2008 21:43 GMT
Thu, 28 Feb 2008 11:09:55 -0800 (PST), /tmw/:

> I am currently running a process in ANT to handle
> the file and was hoping that I could achieve this by using an already
[quoted text clipped - 10 lines]
> hat goes l
> ike this a
[...]

May be something like:

    <replaceregexp file="..." byline="true"
            match=".{10}" replace="\1\r\n" />

Signature

Stanimir

tmw - 29 Feb 2008 18:28 GMT
> Thu, 28 Feb 2008 11:09:55 -0800 (PST), /tmw/:
>
[quoted text clipped - 22 lines]
> --
> Stanimir

I have tried some variations of this without success.  I think this
'replaceregexp' should work with the correct parameters.  Looking for
any ideas on correcting the paramters.  Current example below
literally decides that there are at least 10 chars in the line and
then replaces the first 3 original chars with "lrn".  (instead of
going every 10th char and replacing)

current task:
               <target name="reformatData" depends="init">
                       <replaceregexp
                               byline="true"
                               match=".{10}"
                               replace="\l\r\n">
                               <fileset dir="${data_dir}"
includes="file.txt"/>
                       </replaceregexp>
               </target>

ex: input.txt
some text in a file that rambles on and goes like this

output:
lnre text in a file that rambles on and goes like this

again - any ideas on the parameters goin in (match, replace)
thanks
Arved Sandstrom - 02 Mar 2008 15:37 GMT
[ SNIP ]
>> May be something like:
>>
[quoted text clipped - 10 lines]
> then replaces the first 3 original chars with "lrn".  (instead of
> going every 10th char and replacing)
[ SNIP ]

I haven't used this task at all, but a quick review of the documentation
indicates that it uses some Perl5 type flags. For starters, it looks like
you'd want a flags="g" as an attribute. Also, if you literally want a
newline at every Nth position in the file, I suspect you do not want
"byline", but rather add the 's' flag also (which apparently treats the
entire file as a single string). It also appears that you'll need two
iterations, one to zap the existing newlines, one to put in the new ones.

AHS
Roedy Green - 29 Feb 2008 02:53 GMT
>Trying to format a file by adding a crlf at every Nth position in a
>file.  Not sure what is the best way to do this and looking for ideas
>of how to do it.

See my utility toFixed posted at
http://mindprod.com/jgloss/products.html#TOFIXED

I think I wrote it in C or MASM.  It was a long time ago.

--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.