adding a crlf

T

tmw

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
 
D

Daniele Futtorovic

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

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

Stanimir Stamenkov

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
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
[...]

May be something like:

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

tmw

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
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

[...]

May be something like:

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


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
 
A

Arved Sandstrom

tmw said:
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)
[ 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
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top