Parse a file

FILE1

 
2917,065A,RDF1+TDEV,2917_3RAID5,05E:0_10E:0,BL_lmwsp02,0345,xxx,3452(DR)
2917,03EA,RDF1+TDEV,2917_3RAID5,03E:0_12E:0,BL_tv00p02,0455,xxx,3ee4(DR)
2917,03EB,RDF1+TDEV,2917_3RAID5,03E:0_12E:0,BL_tv00p02,0345,xxx,2d34(DR)
2917,04FE,RDF1+TDEV,2917_3RAID5,05E:0_10E:0,BC_ht00p01,2e22,xxx,3456(DR)

OUTPUT FILE 2

 
0345,RL_lmwsp02
0455,RL_tv00p02
0345,RL_tv00p02
2e22,RC_ht00p01

In file 2 1st column is the 7th column of file 1 and the 2nd column is 6th column of
file 1 with first alphabet replaced by "R"

OUTPUT FILE 3

 
05E:0_10E:0,RL_lmwsp02
03E:0_12E:0,RL_tv00p02
03E:0_12E:0,RL_tv00p02
05E:0_10E:0,RL_ht00p01

In file 3 1st column is the 5th column of file 1 and the 2nd column is 6th column of
file 1 with first alphabet replaced by "R"

OUTPUT FILE 4

3452,DL_lmwsp02
3ee4,DL_tv00p02
2d34,DL_tv00p02
3456,DC_ht00p01

In file4 1st column is the column in file 1 which contains "(DR)" ,which may not always be $9 and the 2nd column is 6th column of
file 1 with first alphabet replaced by "D"

Thanks

awk 'BEGIN{FS=OFS=","}{print $7,"R"substr($6,2) >"FILE2";print $5,"R"substr($6,2) >"FILE3";print gensub(/\(DR\)/,"",1,$NF),"D"substr($6,2) >"FILE4"}' FILE1

Hi yinyuemi ,

the nawk i have on the system does not support gensub ,
nawk: calling undefined function gensub
i tried gsub but get a error ...is there another alternative

Thanks

awk -F"," '{print $7",R"substr($6,2) > "FILE2";print $5",R"substr($6,2) > "FILE3"; print $NF",D"substr($6,2) > "FILE4";}' inputfile

tene,

i want to find the column with (DR) in it ..and print its value without (DR) ...this not doing that
thx

Try this.

awk -F"," '{print $7",R"substr($6,2) > "FILE2";print $5",R"substr($6,2) > "FILE3"; print substr($NF,1,4)",D"substr($6,2) > "FILE4";}' > inputfile

Hi tene ,

sorry about the confusion , only problem is that the column with (DR) in it , may not always be same , so its more like search for the column containing (DR) word and print the value without (DR) ....thx

please try:

awk 'BEGIN{FS=OFS=","}{print $7,"R"substr($6,2) >"FILE2";print $5,"R"substr($6,2) >"FILE3";print substr($NF,1,index($NF,"\(")-1),"D"substr($6,2) >"FILE4"}' FILE1