[HPADM] RE: -SUMMARY2- Insert characters in middle of line

From: Naylor, Jim (Jnaylor@Schnucks.com)
Date: Thu Dec 11 2003 - 09:42:07 EST


Here is one other way from Richard Wright. Thanks Richard.

sed 's/^\(.\{100\}\)\(.*\)$/\100000\2/' infile

Thanks,
Jim Naylor
Unix Systems Administrator
Schnuck Markets, Inc.
* Direct: (314) 994-4784
*)) Cell: (314) 691-0186
* Fax : (314) 994-4684
* jnaylor@schnucks.com

-----Original Message-----
From: Naylor, Jim
Sent: Thursday, December 11, 2003 7:55 AM
To: Naylor, Jim
Subject: RE: [HPADM]-SUMMARY- Insert characters in middle of line

Thanks to Brett Geer, Thierry ITTY, and bill Thompson for there responses.
Here they are:

Brett:
awk '{ printf ("%s00000%s\n", substr ($0, 1, 120), substr ($0, 121)) } ' <
input > output

Thierry:
sed -e 's/^.{119,119}/&00000/' < infile > outfile

should do it
it reads : from the very beginning of the line ( ^ ), take exactly 119
chars ( {119,119} ) whatever they are ( . ) and keep that string ( & ) but
add 00000 just after it ( 00000 ). this will insert the desired string
starting at 120th char

Bill:
For a one time shot you could use the vertical bar option in vi to get to
character position 120 ("|120") then insert after ("a").

If you want to script it here's *one* way (I'm sure there are many):

- - - - - - snip - - - - - -
#!/bin/sh

FILE="yourfile"
TEMPFILE="/tmp/temp.$$"

>$TEMPFILE

IFS="
"

for LINE in $(cat $FILE); do

Once again thanks to all.

Thanks,
Jim Naylor
Unix Systems Administrator
Schnuck Markets, Inc.
* Direct: (314) 994-4784
*)) Cell: (314) 691-0186
* Fax : (314) 994-4684
* jnaylor@schnucks.com

-----Original Message-----
From: Naylor, Jim
Sent: Wednesday, December 10, 2003 4:06 PM
To: Hpux-Admin@Dutchworks. Nl (E-mail)
Subject: [HPADM] Insert characters in middle of line

Good Day All,
I have the need to insert a string of characters/numbers in the middle of a
record that is 240 characters long. Say I have the following filewith two
records:

zzzzzzzzzzzzzzzzzzzzzzzzzzzzwwwwwwwwwwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxx
xxyyyyyyyyyyyyyyyyyyyycccccccccccccccccccccbbbbbbbbbbbbbbbbbbbrrrrrrrrrrrrrr
rrrrrrrrrrrnnnnnnnnnnnnnnnnnnnnnnkkkkkkkkkkkkkkk
aaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccd
ddddddddddddddddddddeeeeeeeeeeeeeeffffffffffffffgggggggggggggggggggggghhhhhh
hhhhhhhhhhhhhhhhiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiijjjjjjjjjjjjjjjjjjjjjjj
jjjjjjjjjjjjjjjjjjjjjjj

I need to insert 00000 starting at position 120 on each record. So each
record would be the same as it was befor but have the additional characters
starting at 120. The result would look somewhat like this:

zzzzzzzzzzzzzzzzzzzzzzzzzzzzwwwwwwwwwwwwwwwwwwwwwwwxxxxx00000xxxxxxxxxxxxxxx
xxxxxxxyyyyyyyyyyyyyyyyyyyycccccccccccccccccccccbbbbbbbbbbbbbbbbbbbrrrrrrrrr
rrrrrrrrrrrrrrrrnnnnnnnnnnnnnnnnnnnnnnkkkkkkkkkkkkkkk
aaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccc00000ccccccccc
ccccdddddddddddddddddddddeeeeeeeeeeeeeeffffffffffffffggggggggggggggggggggggh
hhhhhhhhhhhhhhhhhhhhhiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiijjjjjjjjjjjjjjjjjj
jjjjjjjjjjjjjjjjjjjjjjjjjjjj

Any suggestions would be greatly appreciated.

Thanks,
Jim Naylor
Unix Systems Administrator
Schnuck Markets, Inc.
* Direct: (314) 994-4784
*)) Cell: (314) 691-0186
* Fax : (314) 994-4684
* jnaylor@schnucks.com

--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact
majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner:
owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse
only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse &
search)
--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:37 EDT