Solved

LInux and vi

Posted on 2014-11-17
4
104 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
  • 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 37

Accepted Solution

by:
Gerwin Jansen 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now