search for string and replace backwards

I'm new to Unix scripting and I'm not sure if this can be done. Example:

search (grep) in a file for 'Control ID' and then replace with 4 blanks 7 bytes before 'Control ID.

input
"xxxxxx1234xxxxxxxControl IDxxxxxx"

output:
"xxxxxx xxxxxxxControl IDxxxxxx"

thanks!

Hi.

Using sed:

sed "s/\(.*\)....\(.\{7\}Control ID.*\)/\1 \2/" input_file
 
xxxxxx xxxxxxxControl IDxxxxxx
 

thanks a lot..

Scott,

the command works ok, but 1 space replaces 4 bytes which compresses the file:

sed "s/\(.\)....\(.\{7\}Control ID.\)/\1 \2/"

In:
abcde****1234567Control ID890

to:
abcde 1234567Control ID890

need:
abcdebbbb1234567Control ID890

with b= space

Thanks!

Hi.

Add some spaces between \1 and \2

sed "s/\(.*\)....\(.\{7\}Control ID.*\)/\1    \2/" file2
xxxxxx    xxxxxxxControl IDxxxxxx

Thanks Scott! that worked..

---------- Post updated at 11:12 AM ---------- Previous update was at 09:26 AM ----------

when I try to run this on my production file it does not work. I think it's the file size or record length issue. Does sed have a limit for record lenght? should I try awk instead?

Hi.

No, it doesn't.

I just ran it on a file with a record (line) length of 750,000, and it worked fine.

Please state what the problem is (error message, etc.), and show what you did.

Thanks.

no error messages. nothing happens, looks like it can't find 'Control ID".

When I run this on a small file it works. Could be end of line characters.. not sure.

Background:
This is a AFP file which I converted from ebcdic to ASCII.

when I do a "wc AFP.test1.ascii"

I receive 41 of these messages:
wc: AFP.test1.ascii:41: Invalid or incomplete multibyte or wide character
then...
40 606 10286 AFP.test1.ascii

Not sure if this helps or not.