sed 's/CONVERTED_REC_STATS = /CONVERTED_REC_STATS = ?

hey , i am using shell script to change multiple lines in files in the current directory, when i am runing the script which is present in the same directory changes are being made in the script also.
also when i am trying to make changes in more the one line then it is not able to do it i.e it is not returning the prompt.
code which i am using is

for file in *
    do
        echo "Replacing on : $file"
        sed 's/CONVERTED_REC_STATS = /CONVERTED_REC_STATS =  UNK:/g';'s/REJECTED_REC_STATS = /REJECTED_REC_STATS =  UNK:/g' $file > $file.tmp
        mv $file.tmp $file
        echo "Replacement done on : $file"
done

~
please help
thanks in advance

Try this

sed -e "s/CONVERTED_REC_STATS = /CONVERTED_REC_STATS = UNK:/g" -e "s/REJECTED_REC_STATS =/REJECTED_REC_STATS = UNK:/" $file

Pls use code tags as required by forum rules!

a) Protect you script from modifications by either permissions or by shell mechanisnms. You do not mention what shell you are using; e.g. bash provides sth like !(pattern-list) when extended pattern matching is ON by setting the extglob option.
b) Eliminate the two ' from ';' in the middle of your line.

hey , i used this code for but its not working to change lines in the file

#!/bin/ksh
for file in *
  do
     sed -e "s/CONVERTED_REC_STATS = /CONVERTED_REC_STATS = UNK:/g" -e "s/REJECTED_REC_STATS =/REJECTED_REC_STATS = UNK:/g" -e "s/DISCARDED_REC_STATS =/DISCARDED_REC_STATS = UNK:/g"
     -e "s/ADDED_REC_STATS =/ADDED_REC_STATS = UNK:/-e "s/REC_KEY,ORIG_REC_KEY,DUR_SPAN_ID,CALL_START_DTTM,PREV_CONV_DUR,CONV_DUR,A_PTY_NBR,A_PTY_NBR_TYPE_ID,A_PTY_CELL_ID,A_PTY
     _IMSI,A_PTY_MSRN,B_PTY_NBR,B_PTY_NBR_TYPE_ID,B_PTY_CELL_ID,B_PTY_IMSI,B_PTY_MSRN,IN_TRG_ID,OUT_TRG_ID,CALL_STATUS_ID,SUPP_SVC_ID,PROV_CHG_AMT,GEN_FIELD_1,GEN_FIELD_2,GEN_FIELD_
     3,GEN_FIELD_4,GEN_FIELD_5/"REC_KEY","ORIG_REC_KEY","DUR_SPAN_ID","CALL_START_DTTM","PREV_CONV_DUR","CONV_DUR","A_PTY_NBR","A_PTY_NBR_TYPE_ID","A_PTY_CELL_ID","A_PTY_IMSI","A_P
     TY_MSRN","B_PTY_NBR", "B_PTY_NBR_TYPE_ID","B_PTY_CELL_ID","B_PTY_IMSI","B_PTY_MSRN","IN_TRG_ID","OUT_TRG_ID","CALL_STATUS_ID","SUPP_SVC_ID","PROV_CHG_AMT","GEN_FIELD_1","GEN_F
     IELD_2","GEN_FIELD_ 3","GEN_FIELD_4","GEN_FIELD_5"/g" $file > $file.tmp
  mv $file.tmp $file
done

please help

Without delving into your sed concoction, I noticed you are using double quotes around the substututes statements, but these should be single quotes..

Oh man seems to be lot of changes are required in your file.

If you want to replace the inside record with double quotes. Then try this.

[vikram@lg105m 05:50 vikram]$ cat file3.txt
REC_KEY,ORIG_REC_KEY,DUR_SPAN_ID
[vikram@lg105m 05:50 vikram]$ sed "s/REC_KEY,ORIG_REC_KEY,DUR_SPAN_ID/"'"REC_KEY"'","'"ORIG_REC_KEY"'","'"DUR_SPAN_ID"'"/g" file3.txt
"REC_KEY","ORIG_REC_KEY","DUR_SPAN_ID"

Its just a sample. You can similarly do it for entire records.

1 Like

hey , i am facing a lot of problem in c++ coding ,what should i do , is there any institute in pune which can me.

Why go through all this quoting bonanza? Why not just:

sed 's/REC_KEY,ORIG_REC_KEY,DUR_SPAN_ID/"REC_KEY","ORIG_REC_KEY","DUR_SPAN_ID"/g' file

In fact if the idea is just to put quotes around keys, one could even go:

sed 's/[^,]*/"&"/g' file