# script help

**URL:** <https://community.unix.com/t/script-help/208335>\
**Category:** Shell Programming and Scripting\
**Created:** [August 12, 2008, 2:51am UTC](https://community.unix.com/t/script-help/208335 "2008-08-12T02:51:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohan705](https://community.unix.com/letter_avatar/mohan705/32/6_22734026db12803ebb3e059622ac3534.png) [@mohan705](https://community.unix.com/u/mohan705)\
**Post date:** [August 12, 2008, 2:51am UTC](https://community.unix.com/t/script-help/208335/1 "2008-08-12T02:51:23Z")

</div>

Hi

Below is the i/p of my file ,first read the 1st line of the file 'i.e:SET DBASE\_TARGETTABLE TO 'XX\_SW' and replace with  
SET DBASE\_TARGETTABLE TO 'XX\_tW and read the last line 'i.e : .SET TARGETTABLE TO 'TABLE135044' and replce with i/p file name (If my i/p file name is mm\_customer\_info.txt ,replace with 'TABLE135044' TO 'customer\_info').Any help should be appreciated

# file.txt

.LOGON dn/up\_load1,messwh08;

.SET DBASE\_TARGETTABLE TO 'XX\_SW';  
.SET DBASE\_WORKTABLE TO 'XX\_SW';  
.SET DBASE\_ETTABLE TO 'XX\_SW';  
.SET DBASE\_UVTABLE TO 'XX\_SW';  
.SET TARGETTABLE TO 'TABLE135044';

.BEGIN IMPORT MLOAD

Expecting o/p

.LOGON dn/up\_load1,messwh08;

.SET DBASE\_TARGETTABLE TO 'XX\_tW';  
.SET DBASE\_WORKTABLE TO 'XX\_SW';  
.SET DBASE\_ETTABLE TO 'XX\_SW';  
.SET DBASE\_UVTABLE TO 'XX\_SW';  
.SET TARGETTABLE TO 'cutomer\_info';

.BEGIN IMPORT MLOAD

Thanks,  
MR

---

<div class="post-metadata">

**Author:** ![Annihilannic](https://community.unix.com/user_avatar/community.unix.com/annihilannic/32/4183_2.png) [@Annihilannic](https://community.unix.com/u/Annihilannic)\
**Post date:** [August 12, 2008, 3:16am UTC](https://community.unix.com/t/script-help/208335/2 "2008-08-12T03:16:13Z")

</div>

Have you tried a simple search-and-replace using sed?

---

<div class="post-metadata">

**Author:** ![mohan705](https://community.unix.com/letter_avatar/mohan705/32/6_22734026db12803ebb3e059622ac3534.png) [@mohan705](https://community.unix.com/u/mohan705)\
**Post date:** [August 12, 2008, 3:21am UTC](https://community.unix.com/t/script-help/208335/3 "2008-08-12T03:21:43Z")

</div>

Hi

The last line which is highlighted is dynamic value ,i need to pass i/p files as parameter and replace that value with my i/p file (If my i/p file name is mm\_customer\_info.txt ,replace with 'TABLE135044' TO 'customer\_info')  
.SET TARGETTABLE TO 'TABLE135044';

Thanks  
MR

---

<div class="post-metadata">

**Author:** ![Franklin52](https://community.unix.com/user_avatar/community.unix.com/franklin52/32/500_2.png) [@Franklin52](https://community.unix.com/u/Franklin52)\
**Post date:** [August 12, 2008, 4:44am UTC](https://community.unix.com/t/script-help/208335/4 "2008-08-12T04:44:19Z")

</div>

The filename mm\_customer\_info.txt is passing as a parameter in your script but how do you get the names of the variables: TABLE135044 and customer\_info?

Regards

---

<div class="post-metadata">

**Author:** ![mohan705](https://community.unix.com/letter_avatar/mohan705/32/6_22734026db12803ebb3e059622ac3534.png) [@mohan705](https://community.unix.com/u/mohan705)\
**Post date:** [August 12, 2008, 4:57am UTC](https://community.unix.com/t/script-help/208335/5 "2008-08-12T04:57:01Z")

</div>

Hi

soryy for wrong info

# Customer\_info

.LOGTABLE LOGTABLE135044;  
.LOGON r01gtdn/up\_load1,messwh08;  
.SET DBASE\_TARGETTABLE TO 'DP\_SBDW';  
.SET DBASE\_WORKTABLE TO 'DP\_SBDW';  
.SET DBASE\_ETTABLE TO 'DP\_SBDW';  
.SET DBASE\_UVTABLE TO 'DP\_SBDW';  
.SET TARGETTABLE TO 'TABLE135044';

.BEGIN IMPORT MLOAD

I wrote small script to replace TABLE135044 with input file name but its not working but it creates filename with new

# a2.sh

file=$1  
col=`awk NR==7 $1 |tr " " "\n" |tail -1`  
echo "$col"  
col1=`basename $1 |tr " " "\n" |tail -1`  
echo "$col1"  
sed -e 's/$col/$col1/g' $1 \>$1.new  
~

'TABLE135044';  
Customer\_info

a2.sh Customer\_info

Thanks,  
MR

---

<div class="post-metadata">

**Author:** ![era](https://community.unix.com/letter_avatar/era/32/6_22734026db12803ebb3e059622ac3534.png) [@era](https://community.unix.com/u/era)\
**Post date:** [August 12, 2008, 5:45am UTC](https://community.unix.com/t/script-help/208335/6 "2008-08-12T05:45:21Z")

</div>

You need to use double quotes around the sed script in order for the shell to interpolate the values of the variables $col and $col1; single quotes prevent interpolation. Anyhow, using awk to identify a replacement string for sed seems misdirected, when awk can do the replacement all by itself.

```nohighlight
nawk -v IFS="'" -v basename="`basename "$1"`" '
  /SET DBASE_TARGETTABLE/ { $2 = "XX_tW" }
  /SET TARGETTABLE/ { $2 = basename }
1' "$1"

```

---

<div class="post-metadata">

**Author:** ![mohan705](https://community.unix.com/letter_avatar/mohan705/32/6_22734026db12803ebb3e059622ac3534.png) [@mohan705](https://community.unix.com/u/mohan705)\
**Post date:** [August 12, 2008, 5:56am UTC](https://community.unix.com/t/script-help/208335/7 "2008-08-12T05:56:16Z")

</div>

Hi Era,  
Thanks a lot.Its working fine

Thanks  
MR
