Inserting characters into certain position of file
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix administration > Inserting characters into certain position of file




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Inserting characters into certain position of file  
John


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-11-04 05:34 AM

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.





[ Post a follow-up to this message ]



    Re: Inserting characters into certain position of file  
newsgroup user


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-11-04 06: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





[ Post a follow-up to this message ]



    Re: Inserting characters into certain position of file  
Davide Bianchi


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-11-04 06: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:\>
|
|
|





[ Post a follow-up to this message ]



    Re: Inserting characters into certain position of file  
Simon Strandgaard


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-11-04 10:36 AM

On Wed, 11 Feb 2004 15:17:39 +0100, Måns Rullgård wrote:
> pokechoppe@aol.com (John) writes: 
[snip]
> 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





[ Post a follow-up to this message ]



    Re: Inserting characters into certain position of file  
newsgroup user


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-11-04 10: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





[ Post a follow-up to this message ]



    Re: Inserting characters into certain position of file  
Simon Strandgaard


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-11-04 10: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








[ Post a follow-up to this message ]



    Re: Inserting characters into certain position of file  
newsgroup user


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-11-04 10: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





[ Post a follow-up to this message ]



    Re: Inserting characters into certain position of file  
William Park


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-11-04 11: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.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 05:22 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register