Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Regarding command Uses

2 views
Skip to first unread message

Gourav Khira

unread,
Jan 17, 2013, 1:07:24 AM1/17/13
to bug...@gnu.org
Hi Team,

Actually, i want to replace any word with another.i used "sed" command but
it's not getting properly result.

*For Examples*:

THIS IS 1ST UPPER CASE LINE IN THE FILE.
this is 1st lower case line in the file.

THis is THe the mixed up line.

Ram , Shyam, john, and Mohan are good students.

But somya is not good girl

This .........



If,I want to replace here "this" with "that" using "sed" command.


sed this that | filename


Please suggest me which command is right to use here and revert me ASAP.


Thanks & regards,

Gourav Khira

Bob Proulx

unread,
Jan 17, 2013, 4:16:59 AM1/17/13
to Gourav Khira, bug...@gnu.org
Gourav Khira wrote:
> Actually, i want to replace any word with another.i used "sed" command but
> it's not getting properly result.
> ...
> If,I want to replace here "this" with "that" using "sed" command.
>
> sed this that | filename

The sed manual has an entire section on substituting this for that in
section "3.5 The 's' Command". If sed is installed properly it will
include the documentation. You can read the documentation that is
installed with sed and therefore will be the matching version like
this:

info sed

Also the documentation for the most current release is available
online. The particular section I am referring to is here:

http://www.gnu.org/software/sed/manual/html_node/The-_0022s_0022-Command.html#The-_0022s_0022-Command

As a direct hint you need to do something like this:

sed s/this/that/g filename

If the patterns include any character that is special to the shell
then it will need to be quoted. The prefered Unix/GNU quoting style
is typically the single quote so that all (actually most) characters
are preserved verbatim. Ports to other operating systems may need
other quoting specific to that port.

sed 's/this spaced word/that spaced word/g' filename

Bob

0 new messages