Search for multiple string and replace with respective values

Hi,

Can anyone help me to search for multiple strings within specified position and replace with respective string value.
For example I need to search the string from the position 11 to 20 and if it contain ABC and then replace it by BCDEFGHIJ ... find AABZSDJIK and replace with QWE. and so on.. The file may have 50000 records and I need to search and replace with 10 different values. I can't use perl script please let me know the best way to achive this in UNIX script.

Try using a sed script, e.g...

$ head file1 script1.sed
==> file1 <==
xxxxxxxxxxABCxxxxxxxxxxxxxxxxx
yyyyyyyyyyAABZSDJIKyyyyyyyyyyy
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

==> script1.sed <==
s/\(..........\)ABC/\1BCDEFGHIJ/
s/\(..........\)AABZSDJIK/\1QWE/

$ sed -f script1.sed file1 > file2

$ cat file2
xxxxxxxxxxBCDEFGHIJxxxxxxxxxxxxxxxxx
yyyyyyyyyyQWEyyyyyyyyyyy
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

$

Thanks for your reply. My requirement is slightly different. Search for different set of string and replace with respective value with accurate field position. For example i want to search specific set of strings from 25 to 35 and repalce with corresponding values. If replacing value has 10 character then remaining 5 character should be filled with space so that the next value starting from 36 is not shifted to left column.

 
find from 25 to 35  -- replace with
2FMDK38C39B--AAAAAAAAAAA
1FMEU64    --BBBB       
5LMFU275   --CCCCC      
1ZVHT82H28 --DD         
           --Nodata     
 
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
3FADP4CJ6BM103485FP8FC022FMDK38C39B2010-08-212010-10-20
4M2EU38807UJ02689VT0ZD0M1FMEU64    2008-02-292010-12-27
1FMEU64E39UA36544NS1CD0M5LMFU275   2009-07-042010-12-21
1FAHP2EW0AG131631OQ9AA1A1ZVHT82H28 2010-01-162010-12-21
1FMEU3BE6AUF00576ER9AA1A           2010-08-072010-12-23
1FMEU33E18UB03690FR9AA1A           2008-11-082010-12-23
 
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
3FADP4CJ6BM103485FP8FC02AAAAAAAAAAA2010-08-212010-10-20
4M2EU38807UJ02689VT0ZD0MBBBB       2008-02-292010-12-27
1FMEU64E39UA36544NS1CD0MCCCCC      2009-07-042010-12-21
1FAHP2EW0AG131631OQ9AA1ADD         2010-01-162010-12-21
1FMEU3BE6AUF00576ER9AA1ANodata     2010-08-072010-12-23
1FMEU33E18UB03690FR9AA1ANodata     2008-11-082010-12-23

Can anyone help me to get above result.

Hi.

If you are doing this yourself, perhaps this is something you can build upon. This would need to read in the pairs of strings, old and new, then search each line for old in the second field:

#!/usr/bin/env bash

# @(#) s4	Demonstrate FIELDWIDTH and substitution.

# Utility functions: print-as-echo, print-line-with-visual-space.
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
# Context for local environment.
[ -f ~/bin/context ] && . ~/bin/context awk

FILE=${1-data1}

pl " Data file $FILE:"
cat $FILE

# 1FMEU64    --BBBB
pl " Sample results, awk with FIELDWIDTHS, first pattern only:"
awk '
BEGIN	{ FIELDWIDTHS = " 24 11 80" ; print "FIELDWIDTHS =", FIELDWIDTHS }
$2 ~ /1FMEU64/	{ print ; $2 = "BBBB" ; l = length($3) 
					printf("%24s%-11s%-*s\n",$1,$2,l,$3) }
' $FILE

exit 0

producing:

% ./s4

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.32-5-686, i686
Distribution        : Debian GNU/Linux wheezy/sid 
GNU bash 4.1.5
GNU Awk 3.1.7

-----
 Data file data1:
3FADP4CJ6BM103485FP8FC022FMDK38C39B2010-08-212010-10-20
4M2EU38807UJ02689VT0ZD0M1FMEU64    2008-02-292010-12-27
1FMEU64E39UA36544NS1CD0M5LMFU275   2009-07-042010-12-21
1FAHP2EW0AG131631OQ9AA1A1ZVHT82H28 2010-01-162010-12-21
1FMEU3BE6AUF00576ER9AA1A           2010-08-072010-12-23
1FMEU33E18UB03690FR9AA1A           2008-11-082010-12-23

-----
 Sample results, awk with FIELDWIDTHS, first pattern only:
FIELDWIDTHS =  24 11 80
4M2EU38807UJ02689VT0ZD0M1FMEU64    2008-02-292010-12-27
4M2EU38807UJ02689VT0ZD0MBBBB       2008-02-292010-12-27

Not all versions of gawk that I have encountered handle FIELDWIDTHS correctly.

I think using the builtin function unpack in perl might an alternate method.

Best wishes ... cheers, drl