HELP Need in SED/PERL conditional line replacement

Hi ,

I need some help on perl/sed conditional replacement
The situation is like below .

I have a file contents like below .

AAA|BBB|CCC|DDD
AAA|BCF|CCC|HHH
AAA|BVF|JJJ|KKK

Here in the above file . I know my second column value (taking "|" as my delimited )

Basically I have to search for 2nd columm value and replace the 3rd column value in that pattern matching line to some valu i say .

say I know BBB in my first row .I have to replace CCC with whatever data I send .

Thank in advance

--rob

Something like this?

awk -F"|" '$2=="BBB"{$3=var}1' OFS="|" var="NewValue" file

One more problem now.

Is it possible to pass $values to awk command .

awk -F"|" '$2=="BBB"{$3=var}1' OFS="|" var="NewValue" file

say here I have to variable s="BBB" va="CCC" But I am not able to replace in awk like below

awk -F"|" '$2=="$s"{$3=var}1' OFS="|" var="$va" file

Is it possible to replace like above

Something like this:

awk -F"|" '$2==s{$3=var}1' OFS="|" s="BBB" var="NewValue" file