Solved

LInux and vi

Posted on 2014-11-17
4
102 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
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 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.:
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.

708 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

13 Experts available now in Live!

Get 1:1 Help Now