|
Home > Archive > Unix administration > February 2004 > Inserting characters into certain position of file
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Inserting characters into certain position of file
|
|
|
| I'm still having problems with this subject matter. If I have a line
that is 600 characters long and I need to replace whatever is in
characters (fields) 360 - 364 with the five digit code ABCDE, how do I
do this?
I've tried utilizing sed for this, but I get endpoint too large errors
because I can't run a sed substitute command past 255 characters.
Below is what I've tried to do, but I keep receiving endpoint too
large errors when I put 360 in the command:
sed "/^A00.*${INVNUM}.*${PRODNUM}/s/\([a-zA-Z0-9 ]\{1,360\}\)[a-z
A-Z0-9 ]\{5\}/\1${LINEITNUM}/" $LFILE > $TMPFILE
Please help me put this 2 year old problem of mine officially to rest.
Thank you.
| |
| newsgroup user 2004-02-11, 1:36 am |
| pokechoppe@aol.com (John) writes:
> I'm still having problems with this subject matter. If I have a line
> that is 600 characters long and I need to replace whatever is in
> characters (fields) 360 - 364 with the five digit code ABCDE, how do I
> do this?
>
> I've tried utilizing sed for this, but I get endpoint too large errors
> because I can't run a sed substitute command past 255 characters.
> Below is what I've tried to do, but I keep receiving endpoint too
> large errors when I put 360 in the command:
>
> sed "/^A00.*${INVNUM}.*${PRODNUM}/s/\([a-zA-Z0-9 ]\{1,360\}\)[a-z
> A-Z0-9 ]\{5\}/\1${LINEITNUM}/" $LFILE > $TMPFILE
>
> Please help me put this 2 year old problem of mine officially to rest.
Use PERL instead. It doesn't have any limits on string lengths.
--
Måns Rullgård
mru@kth.se
| |
| Davide Bianchi 2004-02-11, 1:36 am |
| In comp.unix.admin John <pokechoppe@aol.com> wrote:
> I'm still having problems with this subject matter. If I have a line
> that is 600 characters long and I need to replace whatever is in
> characters (fields) 360 - 364 with the five digit code ABCDE, how do I
> do this?
You can use 'head' to extract a number of bytes (chars) from the
beginning of the file and tail to extract a number of bytes from
the end, wc can give you the lenght of the file in bytes.
Davide
--
| Turn your Pentium into a Gameboy: Type WIN at C:\>
|
|
|
| |
| Simon Strandgaard 2004-02-11, 5:36 am |
| On Wed, 11 Feb 2004 15:17:39 +0100, Måns Rullgård wrote:
> pokechoppe@aol.com (John) writes:
[snip][color=blue]
> Use PERL instead. It doesn't have any limits on string lengths.
I can recommend Ruby (IMHO Ruby is nicer than Perl)
server> ruby a.rb
OK
server> cat a.rb
=begin # generate a input data
s = ("."*360) + "xxxxx" + ("_"*235)
raise "should not happen" if s.length != 600
data = s+"\n" + "hello world\n" + s+"\n" + ("t"*601)+"\n" + s
File.open("input", "w+") {|f| f.write(data) }
=end
data = ""
File.open("input", "r") {|f| data = f.read }
re = /^(.{360}).{5}(.{235})$/
data.gsub!(re, '\1ABCDE\2')
File.open("output", "w+") {|f| f.write(data) }
puts "OK"
server>
--
Simon Strandgaard
| |
| newsgroup user 2004-02-11, 5:36 am |
| Simon Strandgaard <neoneye@adslhome.dk> writes:
> On Wed, 11 Feb 2004 15:17:39 +0100, Måns Rullgård wrote:
> [snip]
>
> I can recommend Ruby (IMHO Ruby is nicer than Perl)
I don't know Ruby, but I know that virtually every Unix system has
Perl, whereas only a few have Ruby installed.
--
Måns Rullgård
mru@kth.se
| |
| Simon Strandgaard 2004-02-11, 5:36 am |
| On Wed, 11 Feb 2004 19:19:25 +0100, Måns Rullgård wrote:
> Simon Strandgaard <neoneye@adslhome.dk> writes:
>
>
> I don't know Ruby, but I know that virtually every Unix system has
> Perl, whereas only a few have Ruby installed.
You should give it (Ruby) a try.. its pure object oriented and has
a really nice syntax.
For instance
10.times { puts "hello world" }
is pretty obvious...And also
puts "dlrow olloh".reverse
outputs "hello world"
Everything is an object.. you can invoke methods on numbers, strings..etc.
--
Simon Strandgaard
| |
| newsgroup user 2004-02-11, 5:36 am |
| Simon Strandgaard <neoneye@adslhome.dk> writes:
>
> You should give it (Ruby) a try.. its pure object oriented and has
> a really nice syntax.
>
> For instance
>
> 10.times { puts "hello world" }
print "hello world" x 10;
> is pretty obvious...And also
>
> puts "dlrow olloh".reverse
print scalar reverse "dlrow olloh";
> outputs "hello world"
> Everything is an object.. you can invoke methods on numbers, strings..etc.
That's not the right arguments to convince me. I'm not a fan of
overly object oriented languages.
--
Måns Rullgård
mru@kth.se
| |
| William Park 2004-02-11, 6:34 pm |
| In <comp.unix.admin> John <pokechoppe@aol.com> wrote:
> I'm still having problems with this subject matter. If I have a line
> that is 600 characters long and I need to replace whatever is in
> characters (fields) 360 - 364 with the five digit code ABCDE, how do I
> do this?
>
> I've tried utilizing sed for this, but I get endpoint too large errors
> because I can't run a sed substitute command past 255 characters.
> Below is what I've tried to do, but I keep receiving endpoint too
> large errors when I put 360 in the command:
>
> sed "/^A00.*${INVNUM}.*${PRODNUM}/s/\([a-zA-Z0-9 ]\{1,360\}\)[a-z
> A-Z0-9 ]\{5\}/\1${LINEITNUM}/" $LFILE > $TMPFILE
>
> Please help me put this 2 year old problem of mine officially to rest.
1. Use GNU sed.
2. Play with
cut -c1-359
cut -c360-364
cut -c365-
--
William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
Linux solution for data management and processing.
|
|
|
|
|