adding a crlf

Discussion in 'Java' started by tmw, Feb 28, 2008.

  1. tmw

    tmw Guest

    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
     
    tmw, Feb 28, 2008
    #1
    1. Advertising

  2. On 2008-02-28 20:09 +0100, tmw allegedly wrote:
    > 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.

    --
    DF.
     
    Daniele Futtorovic, Feb 28, 2008
    #2
    1. Advertising

  3. 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" />

    --
    Stanimir
     
    Stanimir Stamenkov, Feb 28, 2008
    #3
  4. tmw

    Roedy Green Guest

    On Thu, 28 Feb 2008 11:09:55 -0800 (PST), tmw <>
    wrote, quoted or indirectly quoted someone who said :

    >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
     
    Roedy Green, Feb 29, 2008
    #4
  5. tmw

    tmw Guest

    On Feb 28, 4:43 pm, Stanimir Stamenkov <> wrote:
    > 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" />
    >
    > --
    > 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
     
    tmw, Feb 29, 2008
    #5
  6. "tmw" <> wrote in message
    news:...
    > On Feb 28, 4:43 pm, Stanimir Stamenkov <> wrote:

    [ SNIP ]
    >> May be something like:
    >>
    >> <replaceregexp file="..." byline="true"
    >> match=".{10}" replace="\1\r\n" />
    >>
    >> --
    >> 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)

    [ 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
     
    Arved Sandstrom, Mar 2, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerry III

    Re: how to check CRLF in C#

    Jerry III, Aug 25, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    807
    Jerry III
    Aug 25, 2003
  2. Kevin Spencer

    Re: how to check CRLF in C#

    Kevin Spencer, Aug 25, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    27,948
    Jerry III
    Aug 27, 2003
  3. Simon Chung-Jen Chuang

    Re: how to check CRLF in C#

    Simon Chung-Jen Chuang, Aug 26, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    419
    Simon Chung-Jen Chuang
    Aug 26, 2003
  4. Jack Wright

    Problem in CRLF in multiline fields

    Jack Wright, Apr 20, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    395
    Jack Wright
    Apr 21, 2004
  5. Michael Persaud

    CRLF How does it work for asp.net???!!

    Michael Persaud, May 27, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    5,919
    Michael Persaud
    May 27, 2004
Loading...

Share This Page