question with fixed separators - SCO

This is a discussion on question with fixed separators - SCO ; Hello Everyone, I am new at this. I am trying to add in "|" separator into an exsisting file. I know how to do this when replacing an exsisting separator. But can it be done when you want to place ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: question with fixed separators

  1. question with fixed separators

    Hello Everyone,

    I am new at this. I am trying to add in "|" separator into an exsisting
    file. I know how to do this when replacing an exsisting separator. But can
    it be done when you want to place the separators at a fixed position on the
    lines.

    For example if I want a separator on position 166, 172,270,277 how would I
    be able to do that(if I can). I would imagine that sed would be best for
    this.

    Thanks in advance
    Jorge



  2. Re: question with fixed separators

    Jorge bichara wrote:
    >Hello Everyone,


    > I am new at this. I am trying to add in "|" separator into an exsisting
    >file. I know how to do this when replacing an exsisting separator. But can
    >it be done when you want to place the separators at a fixed position on the
    >lines.


    >For example if I want a separator on position 166, 172,270,277 how would I
    >be able to do that(if I can). I would imagine that sed would be best for
    >this.



    Well, sed would be slow at it, but maybe that doesn't matter.

    This puts a "|" at position 3 of a file "t"

    echo "|" | dd of=t seek=2 count=1 conv=notrunc bs=1

    --
    tony@aplawrence.com Unix/Linux/Mac OS X resources: http://aplawrence.com
    Get paid for writing about tech: http://aplawrence.com/publish.html



  3. Re: question with fixed separators

    In article , wrote:
    >Jorge bichara wrote:
    >>Hello Everyone,

    >
    >> I am new at this. I am trying to add in "|" separator into an exsisting
    >>file. I know how to do this when replacing an exsisting separator. But can
    >>it be done when you want to place the separators at a fixed position on the
    >>lines.

    >
    >>For example if I want a separator on position 166, 172,270,277 how would I
    >>be able to do that(if I can). I would imagine that sed would be best for
    >>this.

    >
    >
    >Well, sed would be slow at it, but maybe that doesn't matter.
    >
    >This puts a "|" at position 3 of a file "t"
    >
    >echo "|" | dd of=t seek=2 count=1 conv=notrunc bs=1

    You might want to look at cut(1). If I read the page right, you MIGHT be
    able to coerce it to do what you want.

    --
    Larry Rosenman http://www.lerctr.org/~ler
    Phone: +1 972-414-9812 E-Mail: ler@lerctr.org
    US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749

  4. Re: question with fixed separators

    Hi tony thanks for the help.

    It does insert the pipe into the first line. but..

    it replaces what ever charecter is in that position and also only inserts
    the pipe into the first line of the file. I am sure your command can be
    mainipulated to give me what i want but I don't know what some of the things
    in your command stand for. Is there a web site with more examples like yours
    that may also give a breif explanation as to what everthing stands for. If
    not can you breifly breakdown your command . Thanks again

    Jorge



    wrote in message news:bnk13n$f40$1@pcls4.std.com...
    > Jorge bichara wrote:
    > >Hello Everyone,

    >
    > > I am new at this. I am trying to add in "|" separator into an

    exsisting
    > >file. I know how to do this when replacing an exsisting separator. But

    can
    > >it be done when you want to place the separators at a fixed position on

    the
    > >lines.

    >
    > >For example if I want a separator on position 166, 172,270,277 how would

    I
    > >be able to do that(if I can). I would imagine that sed would be best for
    > >this.

    >
    >
    > Well, sed would be slow at it, but maybe that doesn't matter.
    >
    > This puts a "|" at position 3 of a file "t"
    >
    > echo "|" | dd of=t seek=2 count=1 conv=notrunc bs=1
    >
    > --
    > tony@aplawrence.com Unix/Linux/Mac OS X resources: http://aplawrence.com
    > Get paid for writing about tech: http://aplawrence.com/publish.html
    >
    >




  5. Re: question with fixed separators

    In article ,
    Jorge bichara wrote:
    >Hello Everyone,
    >
    > I am new at this. I am trying to add in "|" separator into an exsisting
    >file. I know how to do this when replacing an exsisting separator. But can
    >it be done when you want to place the separators at a fixed position on the
    >lines.
    >
    >For example if I want a separator on position 166, 172,270,277 how would I
    >be able to do that(if I can). I would imagine that sed would be best for
    >this.


    You could use:

    awk '{ printf "%s|%s|%s|%s|%s\n", substr($0,1,165), substr($0,166,171),
    substr($0,172,269), substr($0,270,276), substr($0,277) }'

    Or if you have gawk installed:

    gawk 'BEGIN { FS = OFS = "" }
    { $166="|"$166; $172="|"$172; $270="|"$270; $277="|"$277 } 1'

    Or:

    gawk 'BEGIN { FIELDWIDTHS = "165 6 98 7" }
    { printf "%s|%s|%s|%s|%s\n", $1, $2, $3, $4, substr($0,277} }'

    These all assume that you actually have at least 277 characters on each line.
    If not, you can pad the input line first.

    John
    --
    John DuBois spcecdt@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/

  6. Re: question with fixed separators

    In article <3f9ecc50$0$3746$8eec23a@newsreader.tycho.net>,
    John DuBois wrote:
    >gawk 'BEGIN { FIELDWIDTHS = "165 6 98 7" }
    >{ printf "%s|%s|%s|%s|%s\n", $1, $2, $3, $4, substr($0,277} }'


    Even more obscure (there *had* to be a way of fitting this one line

    gawk 'BEGIN{FIELDWIDTHS="165 6 98 7";OFS="|"}{$5=substr($0,277)}1'

    John
    --
    John DuBois spcecdt@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/

  7. Re: question with fixed separators

    Jorge bichara wrote:
    >Hi tony thanks for the help.


    >It does insert the pipe into the first line. but..


    >it replaces what ever charecter is in that position and also only inserts
    >the pipe into the first line of the file. I am sure your command can be
    >mainipulated to give me what i want but I don't know what some of the things
    >in your command stand for. Is there a web site with more examples like yours
    >that may also give a breif explanation as to what everthing stands for. If
    >not can you breifly breakdown your command . Thanks again


    Never mind. Not what you want. Use Perl or sed.


    --
    tony@aplawrence.com Unix/Linux/Mac OS X resources: http://aplawrence.com
    Get paid for writing about tech: http://aplawrence.com/publish.html

+ Reply to Thread