Welcome to Soft32 Linux Forums!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

search string and replace in shell

 
   Soft32 Home -> Linux -> Red Hat RSS
Next:  Accepted vite 1.0+svn834-1 (source amd64)  
Author Message
Obama

External


Since: Aug 18, 2009
Posts: 1



(Msg. 1) Posted: Tue Aug 18, 2009 4:43 pm
Post subject: search string and replace in shell
Archived from groups: alt>os>linux>redhat (more info?)

I do have a file that contains the following line:

This the only one in shell
That are the only one in shell
This is the shell
---
--

what I need is to search each line that starts with "This" and also
line
contains "shell" then replace shell with word "fish"
unfortunately I get this to work your help will be appricated in
advance..

Here is the code:
file=$1
replace=$2

sed -i.backup -e "s/\(^This\)\(..*$\)\(shell\)/\(^This\)\(..*$\)\1$
{replace}/" $file
Back to top
Login to vote
Allen Kistler

External


Since: Jul 12, 2004
Posts: 94



(Msg. 2) Posted: Tue Aug 18, 2009 9:24 pm
Post subject: Re: search string and replace in shell [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Obama wrote:
> I do have a file that contains the following line:
>
> This the only one in shell
> That are the only one in shell
> This is the shell
> ---
> --
>
> what I need is to search each line that starts with "This" and also
> line
> contains "shell" then replace shell with word "fish"
> unfortunately I get this to work your help will be appricated in
> advance..
>
> [snip]

Taking a little extra liberty to help insure "This" and "shell" are
whole words:

sed -e '/^This /s/ shell/ fish/'

Of course, "This is a shellfish." would come out "This is a fishfish."
But I expect you're really doing something not quite the same as you
represent.

Or is this a homework assignment?
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Dovecot question - Hi, I setting up a new mail server with postfix for smtp and dovecot for pop3 on a CentOS 4 machine. Both postfix..

Download Linux eBooks for Red Hat Certifications -- Free - [b:eef70ab027]For RHCE, RHCT, RHCA, RHCSS Aspirants [/b:eef70ab027]..

[gentoo-dev] Replace 'sash' with 'busybox' as our static r.. - i dont want to discuss the logistics of how this will be done just yet ... the idea is to remove 'sash' from our syste...

[patch] some scripts: replace gawk, head, bc with shell, u.. - scripts: replace gawk, head, bc with shell, update Replacing overhead of using some (external) programs instead of...

Bug#211827: search.debian.org: search for Language English.. - Package: www.debian.org Version: unavailable; reported 2003-09-20 Severity: normal Hi, I just entered..

Bug#341149: Cannot search contents of testing AMD64 packag.. - Package: www.debian.org Severity: important The following is using the search box at:..
       Soft32 Home -> Linux -> Red Hat All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Categories:
 Windows
  Linux
 Mac
 PDA


[ Contact us | Terms of Service/Privacy Policy ]