LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-20-2004, 11:18 AM   #1
mijohnst
Member
 
Registered: Nov 2003
Location: Huntsville, AL
Distribution: RHEL, Solaris, OSX, SuSE
Posts: 419

Rep: Reputation: 31
find/change text in VI


I'm trying to figure out how to replace a sentence within a short bash script I wrote, but I can't get the syntax right. I'm hoping someone here can help.

If I have a file that I want to change a sentence into just one word, what command would I use? For example:

# Bash File1
ssh machine1 /etc/rc.d/init.d/gmond restart
ssh machine2 /etc/rc.d/init.d/gmond restart
ssh machine3 /etc/rc.d/init.d/gmond restart
ssh machine4 /etc/rc.d/init.d/gmond restart
ssh machine5 /etc/rc.d/init.d/gmond restart

What I want it to look like:

# Bash File2
ssh machine1 halt
ssh machine2 halt
ssh machine3 halt
ssh machine4 halt
ssh machine5 halt

I thought the command was something like

:%s/[/etc/rc.d/init.d/gmond]/halt/g

But that doesn't work right. Is there an easy way to make these changes? As always, thanks for your help.

Last edited by mijohnst; 12-20-2004 at 11:19 AM.
 
Old 12-20-2004, 11:23 AM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
:x,ys/[/etc/rc.d/init.d/gmond]/halt/g where x = the first line to start on and y equals the last line to consider.

so if you wanted to run the search and replace on lines 10-100 you'd do :10,100s.......
 
Old 12-20-2004, 11:25 AM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Code:
:%s/[/etc/rc.d/init.d/gmond]/halt/g
Quite close :)

Try
Code:
:%s/\/etc\/rc.d\/init.d\/gmond/halt/g
instead ...


The [] doesn't work because that makes your search
look for characters out of that selection, not for that
group...


Cheers,
Tink

Last edited by Tinkster; 12-20-2004 at 11:28 AM.
 
Old 12-20-2004, 11:53 AM   #4
mijohnst
Member
 
Registered: Nov 2003
Location: Huntsville, AL
Distribution: RHEL, Solaris, OSX, SuSE
Posts: 419

Original Poster
Rep: Reputation: 31
You guys are awesome.. thanks so much!
 
Old 12-20-2004, 02:01 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Pleasure :)



Cheers,
Tink
 
Old 12-20-2004, 04:37 PM   #6
shengchieh
Member
 
Registered: Jul 2004
Location: Palo Alto, CA
Distribution: #! Korora
Posts: 472

Rep: Reputation: 30
And if u don't know the line #s, use something like

:s/<old>/<new>/#

where # is the number of lines.

Sheng-Chieh
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How change text color using linux in text mode only runlevel 3? Xavius Linux - General 7 05-07-2009 02:19 AM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM
linux 'find' to find text files subu_s Programming 2 12-02-2004 02:56 AM
How to change text mode thrix Linux - General 4 01-21-2004 03:13 PM
how do i change text colors rcjoyner Linux - Newbie 3 10-16-2003 11:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration