In csv file couple of lines dont fit the data I need.For example, this is my example.csv file:14/Feb/2016:13:21:33-0500,mk15/Feb/2016:14:21:33-0500,mk16/Feb/2016:15:21:33-0500]http://map1.link.de/mk17/Feb/2016:16:21:33-0500]http://map5.link.de/mkI can fetch that lines and correct them with:$ cat example.csv | grep map | sed 's/\(.*\)].*\/\(.*$\)/\1,\2/'Result:16/Feb/2016:15:21:33-0500,mk17/Feb/2016:16:21:33-0500,mkBut what I really want is to correct them and save them like that in the same file. How can I do that?
How to rewrite lines in file?
text processing;files;csv
If you are using GNU Sed, just run:sed -i '/map/s/\(.*\)].*\/\(.*$\)/\1,\2/' example.csvWarning: This will overwrite the contents of the file.  Make a copy first if you're not sure the regex is exactly what you want.If you don't have GNU Sed, or you just want a more portable solution that will run on any POSIX system, use ex:For a trial run without editing the file:printf '%s\n' 'g/map/s/\].*\/\([^/]*\)$/,\1/' %p | ex example.csvTo save changes once you're happy with the result:printf '%s\n' 'g/map/s/\].*\/\([^/]*\)$/,\1/' x | ex example.csv