Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8074399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:38:05+00:00 2026-06-05T14:38:05+00:00

Using VI replacing the first occurrence/instance is pretty simple. :%s/search/replace/args but, here is my

  • 0

Using VI replacing the first occurrence/instance is pretty simple.

    :%s/search/replace/args

but, here is my data set in a .csv format/file:

"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’ll notice in the first line, there are 4 columns, this is the ideal line for the .csv format.

However, in the second line, there are 4 columns, but the first column only accepts ip addresses and nothing more, so 192.168.2.2/driving/is/fun must be removed or seperated with a “,” .csv delimter.

In vi, I was able to use the following:

    :/^"\d\{,3}\.\d\{,3}\.\d\{,3}\.\d\{,3}\//s/\//","/

which does the following:

  • /^”\d{,3}.\d{,3}.\d{,3}.\d{,3}/ – Sets an anchor to start the search at the first IP with a forward slash /. For example, line 2: “192.168.2.2/

  • /s///”,”/ – replaces the / at the end of the IP address and substitutes it with a .csv delimiter “,”

This works great in VI/VIM, replaces exactly what I need one line at a time. However, the data set is much much larger and manually using the following vi search and replace is time consuming. I am looking to script it or find an alternative solution because VI/VIM will only do it one line at a time, the following :s/search/replace/g replaces every / on the line changing the date column in addition.

Obviously, I’ve tried the following:

Adding the % for the whole file inside of the start of the substitution like so:

    :/^"\d\{,3}\.\d\{,3}\.\d\{,3}\.\d\{,3}\//%s/\//","/

which highlights every entry I need to modify but errors out:

    E492: Not an editor command: /^"\d\{,3}\.\d\{,3}\.\d\{,3}\.\d\{,3}\//%s/\//

which is rather confusing.

I would ultimately like to use sed/perl to script the editing of the whole file in one shot.

so..

“192.168.2.2/ –> “192.168.2.2”,”

First occurrence on every line.

Any help will be greatly appreciated..

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:38:06+00:00Added an answer on June 5, 2026 at 2:38 pm

    In ViM, try:

     :%s/^\("\d\{,3}\.\d\{,3}\.\d\{,3}\.\d\{,3}\)\(\/[^"]\)/\1","\2
    

    That is, instead of a search/substitute I use a global (% is shortcut for 1,$ i.e from first line to last line) substitution. I moved your search pattern into the substitution pattern and capture the ip address and the path in separate groups. Then replace them back, squeezing "," in between.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATED SCRIPT I'M USING THAT CAUSES LOCKUP...I tried replacing the (Replace:=wdReplaceOne) with (Replace:=wdReplaceAll), but
I'm replacing some text using a regex that I've found here . $items =
I'm looking for a way to write a search and replace method using W3C
I'm using this but it's replacing single occurances of a new line with <br/><br/>
I need to replace ||| from all the input fields using jquery. But it
Replacing the Special Character using Perl while i am doing this . I got
I'm replacing some text with cufon on my page and I'm using jquery stylish
I'm trying to access to our appliance machine name using: http://<APPLIANCE-HOSTNAME>:19900/xmlfeed (of course replacing
Using PyGtk's IconView, I can set the icons to be reorderable by calling gtk.IconView.set_reorderable(True)
I am trying to craft a macro replacing newlines. My first try was: define(`m4_pascal_str',`

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.