RE: Replace a string inside a file
From: Sites, Brad (BSites_at_mem-ins.com)
Date: 09/15/03
- Previous message: Keith Birchfield: "Replace a string inside a file"
- Maybe in reply to: Keith Birchfield: "Replace a string inside a file"
- Next in thread: Sean Estabrooks: "Re: Replace a string inside a file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: "'redhat-list@redhat.com'" <redhat-list@redhat.com> Date: Mon, 15 Sep 2003 14:10:14 -0500
Keith Birchfield wrote:
> Hello all, and thanks for previous help! :-)
>
> Can anyone give me a csh cheat to copy a file with a specific string
> replaced with another?
>
> For example
> copy foo1.txt to foo2.txt and replace each instance of "blue" with
> "red" where
> foo1.txt contains
> apple
> blue syrup
> green apples
> blue
> red grapes
> grapes
>
> and the resulting foo2.txt contains
> apple
> red syrup
> green apples
> red
> red grapes
> grapes
>
cat foo1.txt |sed 's/blue/red/' > foo2.txt
If you have in foo1.txt the text 'bluegreen apples', the above would change
it to be 'redgreen apples'. To separate out the words as single words do:
cat foo1.txt |sed 's/blue /red /' > foo2.txt.
Or do man sed for further information on ways to do the search and replace
you are wanting to do.
.~. Brad Sites
/V\ Systems Administrator
// \\ Missouri Employers Mutual Insurance
/( )\ bsites@mem-ins.com www.mem-ins.com
^^-^^ (573) 499-4230
-- redhat-list mailing list unsubscribe mailto:redhat-list-request@redhat.com?subject=unsubscribe https://www.redhat.com/mailman/listinfo/redhat-list
- Previous message: Keith Birchfield: "Replace a string inside a file"
- Maybe in reply to: Keith Birchfield: "Replace a string inside a file"
- Next in thread: Sean Estabrooks: "Re: Replace a string inside a file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|