But I wanted to make it in one command so that it works for both type of file. I know I can do with sed command sed -i "s/$PPK/$NPK/" $FileName but it replaces the value in other columns as well so can anyone suggest what can be done ?
Here ColumnNo is the nth column from which I wanted to replace PPK to NPK.
Please find other details
uname -a
Linux XXXXXXX 2.6.32-220.25.1.el6.x86_64 #1 SMP Tue Aug 14 13:14:38 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux
echo $SHELL
/bin/ksh
echo $KSH_VERSION
Version JM 93t+ 2010-06-21
awk -v COL=$ColumnNo -v SRCH="$PPK" -v REP="$NPK" '
{FS=OFS="\""; $0=$0 # recalculate fields based on " delimiter
for (i=2; i<=NF; i+=2) gsub (SEP,"\001", $i) # replace , in " delimited fields with a token
FS=OFS=SEP; $0=$0 # recalculate fields based on , delimiter
sub (SRCH, REP, $COL) # do whatever you need
gsub ("\001", SEP) # just before printing anything, put back the inner ","
}
1
' SEP="," file