Bash script - bulk modifying sed regular expression files

I have a set of .csv files (all in one folder) in the format shown below:

170;151;104;137;190;125;170;108
195;192;164;195;171;121;133;104
... (a lot more rows) ...

The thing is, I messed up a bit, and it should look like this.

170;151;104.137;190.125;170;108
195;192;164.195;171.121;133;104 

If the difference is too subtle to notice:

I need to write a script that changes every third and fifth semicolon to the period in each line of the efery file in this folder.

My research shows that I have to come up with a smart command sed s/in my script. The problem is that I am not very good at regular expressions. From reading the textbook, he is likely to include something with / 3 and / 5.

+5
source share
2 answers

Here is a very short way to do this:

sed 's/;/./3;s/;/./4' -iBAK *

, ( ) ; ..

( sample.txt):

$ sed 's/;/./3;s/;/./4' <sample.txt
170;151;104.137;190.125;170;108
195;192;164.195;171.121;133;104

<WHATEVER>.BAK. , -iBAK -i.


script , Mac 10.8 BSD sed ( , ) Linux sed (gsed) 4.1.4 (2003). @JonathanLeffler , POSIX sed 2008 . .


: bash, :

sed -es/\;/./{3,4} -i *
+4

:

sed -i 's/^\([^;]*;[^;]*;[^;]*\);\([^;]*;[^;]*\);/\1.\2./' foldername/*

( : , sed . , , , , , . .)

+1

All Articles