I have this regex:
sed "{
s/\(.*,\)\(yes\)\(.*\)/\1true\3/
s/\(.*,\)\(no\)\(.*\)/\1false\3/
/\(.*,\)[^yes-no],.*/d
}" student-mat.csv
But when I run it, it returns the following error:
sed: -e expresión #1, carácter 89: Final de rango inválido
I have modified this part: [^yes-no],
for this other: [^yes|no],
since it seems that the range was not detected correctly. In this way the error disappears but it does not make the change well.
The idea is that you modify all yes
by true
and all no
by false
.
The structure of .csv
the is as follows:
school sex age address famsize Pstatus Medu Fedu Mjob Fjob reason guardian traveltime studytime failures schoolsup famsup paid activities nursery higher internet romantic famrel freetime goout Dalc Walc health absences G1 G2 G3
GP F 18 U GT3 A 4 4 at_home teacher course mother 2 2 0 yes no no no yes yes no no 4 3 4 1 1 3 6 5 6 6
GP F 17 U GT3 T 1 1 at_home other course father 1 2 0 no yes no no no yes yes no 5 3 3 1 1 3 4 5 5 6
GP F 15 U LE3 T 1 1 at_home other other mother 1 2 3 yes no yes no yes yes yes no 4 3 2 2 3 3 10 7 8 10
GP F 15 U GT3 T 4 2 health services home mother 1 3 0 no yes yes yes yes yes yes yes 3 2 2 1 1 5 2 15 14 15
GP F 16 U GT3 T 3 3 other other home father 1 2 0 no yes yes no yes yes no no 4 3 2 1 2 5 4 6 10 10
GP M 16 U LE3 T 4 3 services other reputation mother 1 2 0 no yes yes yes yes yes yes no 5 4 2 1 2 5 10 15 15 15
When executing the command, it only modifies the last 2 values it finds, but no others. How can I solve that?
Edited answer:
Thanks to the contribution of @Cuauhtli, I consider that this solution is better than my initial answer (using pipes that took more time to open the program
sed
and process the text several times instead of just once):Initial response:
And chaining commands
sed
with pipes doesn't work for you?Something like:
That would create the file
student-mat-fixed.csv
with the changes you request.