bash - sed -i with process substitution -


i want search grades , replace them compliments follows:

input_q1.csv: roll,name,total,rank,grade 001,a b,78,23,c 003,f yz,100,1,* 004,g h,12,112,f 

output as:

input_q1.csv: roll,name,total,rank,grade 001,a b,78,23,average 003,f yz,100,1,good 004,g h,12,112,fail 

and here code:

#!/bin/bash if cut -d"," -f5 input_q1.csv  | grep -q "\*\|a"; sed  -i 's/\*/good/g;s/a/good/g' <(cut -d"," -f5 input_q1.csv) fi if cut -d"," -f5 input_q1.csv  | grep -q "b\|c"; sed  -i 's/b/average/g;s/c/average/g' <(cut -d"," -f5 input_q1.csv) fi if cut -d"," -f5 input_q1.csv  | grep -q "d"; sed  -i 's/d/poor/g;' <(cut -d"," -f5 input_q1.csv) fi if cut -d"," -f5 input_q1.csv  | grep -q "f"; sed  -i 's/f/fail/g' <(cut -d"," -f5 input_q1.csv) fi 

i want overwrite original file i.e, input_q1.csv know process substitution creates temporary file due passing sed command can't access original file. there alternative way it?

create file e.g. sed.dat:

s/,\*$/,good/ s/,a$/,good/ s/,b$/,average/ s/,c$/,average/ s/,d$/,poor/ s/,f$/,fail/ 

and use:

sed -f sed.dat input_q1.csv 

output:

 roll,name,total,rank,grade 001,a b,78,23,average 003,f yz,100,1,good 004,g h,12,112,fail 

if want edit file input_q1.csv "in place" add sed's option -i.


Comments