Professional Web Applications Themes

Inserting characters into certain position of file - UNIX Programming

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\}/

${LINEITNUM}/" $LFILE > $TMPFILE Please help me put ...

  1. #1

    Default 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.
    John Guest

  2. #2

    Default Re: Inserting characters into certain position of file

    com (John) writes:
     

    Use Perl instead. It doesn't have any limits on string lengths.

    --
    Måns Rullgård
    se
    Måns Guest

  3. #3

    Default Re: Inserting characters into certain position of file

    In comp.unix.admin John <com> wrote: 

    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:\>
    |
    |
    |
    Davide Guest

  4. #4

    Default Re: Inserting characters into certain position of file

    On Wed, 11 Feb 2004 15:17:39 +0100, Måns Rullgård wrote: [/ref]
    [snip] 

    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) + "xx" + ("_"*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
    Simon Guest

  5. #5

    Default Re: Inserting characters into certain position of file

    Simon Strandgaard <dk> writes:
     [/ref]
    > [snip] 
    >
    > I can recommend Ruby (IMHO Ruby is nicer than Perl)[/ref]

    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
    se
    Måns Guest

  6. #6

    Default Re: Inserting characters into certain position of file

    On Wed, 11 Feb 2004 19:19:25 +0100, Måns Rullgård wrote:
     
    >> [snip] 
    >>
    >> I can recommend Ruby (IMHO Ruby is nicer than Perl)[/ref]
    >
    > I don't know Ruby, but I know that virtually every Unix system has
    > Perl, whereas only a few have Ruby installed.[/ref]

    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



    Simon Guest

  7. #7

    Default Re: Inserting characters into certain position of file

    Simon Strandgaard <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" }[/ref]

    print "hello world" x 10;
     

    print scalar reverse "dlrow olloh";
     

    That's not the right arguments to convince me. I'm not a fan of
    overly object oriented languages.

    --
    Måns Rullgård
    se
    Måns Guest

  8. #8

    Default Re: Inserting characters into certain position of file

    On Wed, 11 Feb 2004 20:04:02 +0100, Måns Rullgård wrote: 
    >>
    >> You should give it (Ruby) a try.. its pure object oriented and has
    >> a really nice syntax.[/ref][/ref]
    [snip] 
    >
    > That's not the right arguments to convince me. I'm not a fan of
    > overly object oriented languages.[/ref]

    Fair enough.
    Since you didn't knew Ruby, I felt like wanting to sell Ruby to you ;-)

    Before Ruby I did C/C++ and felt its OO features ed,
    then I discovered Ruby and its OO is sweet, those things
    which C++ lacks, Ruby has. I have only tried a little perl, and
    didn't felt comfordable with it.

    --
    Simon Strandgaard



    Simon Guest

  9. #9

    Default Re: Inserting characters into certain position of file

    In <comp.unix.admin> John <com> wrote: 

    1. Use GNU sed.

    2. Play with
    cut -c1-359
    cut -c360-364
    cut -c365-

    --
    William Park, Open Geometry Consulting, <ca>
    Linux solution for data management and processing.
    William Guest

Similar Threads

  1. Question example for inserting double byte characters into db2 database in vb.net
    By Unregistered in forum Brainstorming Area
    Replies: 0
    Last Post: September 10th, 10:01 AM
  2. Inserting Special Characters
    By eagle in forum ASP.NET Data Grid Control
    Replies: 3
    Last Post: November 29th, 08:04 AM
  3. Inserting characters in Illustrator 9.0
    By Jennifer_McClure@adobeforums.com in forum Adobe Illustrator Windows
    Replies: 5
    Last Post: April 20th, 03:33 PM
  4. Inserting characters into certain position of file
    By John in forum Linux / Unix Administration
    Replies: 7
    Last Post: February 12th, 07:26 AM
  5. Parsing string and inserting characters into it.
    By Aaron Bertrand - MVP in forum ASP
    Replies: 2
    Last Post: July 10th, 10:28 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139