J
John Howard
I need to edit a file and add tokens at aribrary positions on a line or
lines.
I tried doing this with sed but its clumsy (sed can do it for fixed
locations but not arbitrary).
For example, if I have a file with lines that may be up to 255 chars
wide, I need to place tokens at, say, near the 100 char position, the
150th, the 200th, etc.
The position is arbitrary because it depends on the nearest comma
before that
position. Basically, the lines consist of words separated by commas. I
need to place tokens just after the nearest comma prior to those
positions. The positions are relative because the lines vary in length
(if that makes sense).
The lines also consist of trailing blanks and some tabs. I'm stripping
the trailing blanks and changing the tabs to spaces with sed but it
would probably be better if I did that at the same time with the same
bit of Perl. (Nothing wrong with using sed here but it makes sense to
just do it all at once with Perl. With sed I am using an intermediate
file but I understand I can edit the file in question in situ with
Perl.)
Can anyone help me with an example?
Thanks in advance.
lines.
I tried doing this with sed but its clumsy (sed can do it for fixed
locations but not arbitrary).
For example, if I have a file with lines that may be up to 255 chars
wide, I need to place tokens at, say, near the 100 char position, the
150th, the 200th, etc.
The position is arbitrary because it depends on the nearest comma
before that
position. Basically, the lines consist of words separated by commas. I
need to place tokens just after the nearest comma prior to those
positions. The positions are relative because the lines vary in length
(if that makes sense).
The lines also consist of trailing blanks and some tabs. I'm stripping
the trailing blanks and changing the tabs to spaces with sed but it
would probably be better if I did that at the same time with the same
bit of Perl. (Nothing wrong with using sed here but it makes sense to
just do it all at once with Perl. With sed I am using an intermediate
file but I understand I can edit the file in question in situ with
Perl.)
Can anyone help me with an example?
Thanks in advance.