Using a VI to replace the first occurrence / instance is pretty simple.
:%s/search/replace/args
but here is my dataset in .csv / file format:
"192.168.2.1","www.google.com","2009/01/11_10:00"," What a great website" "192.168.2.2/driving/is/fun","-","2009/03/22_00:00","Driving website" "192.168.2.4/boating/is/crazy","-","2009/03/22_00:00","Boating Website" "192.168.2.5","www.cars.com","2009/04/27_00:00","What a good car website"
So, you will notice that there are 4 columns in the first row, this is an ideal line for the .csv format.
However, there are 4 columns in the second row, but the first column only accepts IP addresses and nothing else, so 192.168.2.2/driving/is/fun must be deleted or separated using ",". Csv delimter.
In vi, I was able to use the following:
:/^"\d\{,3}\.\d\{,3}\.\d\{,3}\.\d\{,3}\//s/\//","/
which performs the following actions:
/ ^ "\ d {, 3}. \ d {, 3}. \ d {, 3}. \ d {, 3} / - Sets the binding to start the search by the first IP address using, for example, line 2:" 192.168.2.2/
/ s /// "," / - replaces / at the end of the IP address and replaces it with the delimiter .csv ","
This works fine in VI / VIM, replacing exactly what I need one line at a time. However, the data set is much larger and manual, using the following search and replace vi, is time consuming. I am looking for a script for it or finding an alternative solution, because VI / VIM will only do one line at a time, the following: s / search / replace / g replaces everything / on the line, also changing the date column.
Obviously I tried the following:
Adding% for the whole file at the beginning of the substitution like this:
:/^"\d\{,3}\.\d\{,3}\.\d\{,3}\.\d\{,3}\//%s/\//","/
which highlights every entry I need to change, but errors:
E492: Not an editor command: /^"\d\{,3}\.\d\{,3}\.\d\{,3}\.\d\{,3}\//%s/\//
which is pretty confusing.
Ultimately, I would like to use sed / perl for the script to edit the entire file in one shot.
So..
"192.168.2.2/->" 192.168.2.2 ","
The first occurrence in each line.
Any help would be greatly appreciated.
Thanks!