Solved

LInux and vi

Posted on 2014-11-17
4
108 Views
Last Modified: 2014-11-18
Using vi, I need to search for all occurances of 8585 and replace it with 8586 in a single command

How can I do this?

Thanks
0
Comment
Question by:Anthony Lucia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Assisted Solution

by:Dave Gould
Dave Gould earned 250 total points
ID: 40447445
Escape
:1,$s/8585/8586/g
0
 
LVL 5

Assisted Solution

by:Dave Gould
Dave Gould earned 250 total points
ID: 40447457
To explain:
1,$ = from line 1 to end of file

s/8585/8586/ = substitute 8585 with 8586 . The / char can be replaced by almost any other character - some people prefer #, for example, especially when manipulating paths in a file

g = global ie it will change all occurences of 8585 if there are more than one occurence on a single line
0
 
LVL 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 125 total points
ID: 40447562
:%s/8585/8586/g

2 characters less :)

% means every line in the file
0
 
LVL 25

Assisted Solution

by:madunix
madunix earned 125 total points
ID: 40447836
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question