Discussion:
question with fixed separators
(too old to reply)
Jorge bichara
2003-10-27 20:30:22 UTC
Permalink
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
t***@aplawrence.com
2003-10-27 21:01:43 UTC
Permalink
Post by Jorge bichara
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

--
***@aplawrence.com Unix/Linux/Mac OS X resources: http://aplawrence.com
Get paid for writing about tech: http://aplawrence.com/publish.html
Larry Rosenman
2003-10-28 06:11:57 UTC
Permalink
Post by t***@aplawrence.com
Post by Jorge bichara
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: ***@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749
Jorge bichara
2003-10-28 15:10:20 UTC
Permalink
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
Post by t***@aplawrence.com
Post by Jorge bichara
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
--
Get paid for writing about tech: http://aplawrence.com/publish.html
t***@aplawrence.com
2003-10-28 21:25:56 UTC
Permalink
Post by Jorge bichara
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.


--
***@aplawrence.com Unix/Linux/Mac OS X resources: http://aplawrence.com
Get paid for writing about tech: http://aplawrence.com/publish.html
John DuBois
2003-10-28 20:06:41 UTC
Permalink
Post by Jorge bichara
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 ***@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
John DuBois
2003-10-28 20:27:20 UTC
Permalink
Post by John DuBois
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 ***@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
Loading...