The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 03-26-2007
vino's Avatar
vino vino is offline
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,643
Since your input parameter $1 is of the form pattern/replacement, you can use it to your advantage.

Code:
[/tmp]$ cat try.ksh
#! /bin/ksh

echo $1

par=$(echo $1 | tr  ','  ' ')
echo $par
finalPattern=""
for pattern in $par
do
    finalPattern=${finalPattern}"s/$pattern/g;"
done

sed -e "${finalPattern}" $2
[/tmp]$ cat in
p1 w1
p2 p1 w1 w3
p3 p4
p33 p2 p24 p1 p4
p4 p2
p2
p1
[/tmp]$ ./try.ksh p1/w1,p2/w2,p3/w3,p4/w4 in
p1/w1,p2/w2,p3/w3,p4/w4
p1/w1 p2/w2 p3/w3 p4/w4
w1 w1
w2 w1 w1 w3
w3 w4
w33 w2 w24 w1 w4
w4 w2
w2
w1
[/tmp]$
Reply With Quote