1848649 Members
5549 Online
104034 Solutions
New Discussion

Re: change characters

 
SOLVED
Go to solution
juno2
Super Advisor

change characters

is there any command that can change all the words (eg. yes ) in a file to other words ( eg. no ) ?

# vi abc.txt

1. yes
2. yes
3. yes

change to

vi abc.txt
1. no
2. no
3. no
6 REPLIES 6
Rajeev  Shukla
Honored Contributor
Solution

Re: change characters

Yes,run
sed 's/yes/no/g' abc.txt >abc1.txt
then move the fine back
mv abc1.txt abc.txt


Cheers
Rajeev
Michael Tully
Honored Contributor

Re: change characters

Just a slightly different version from inside the file. This is for occurances on all lines. If it is only the first occurance, the drop the 'g' at the end.

# vi abc.txt

:1,$s/yes/no/g
ESC
:x!

Anyone for a Mutiny ?
juno2
Super Advisor

Re: change characters

thx all
Stuart Abramson_2
Honored Contributor

Re: change characters

You should assign points to the above answerers.
Paddy_1
Valued Contributor

Re: change characters

tr 'yes' 'no' < abc.txt > new_abc.txt
The sufficiency of my merit is to know that my merit is NOT sufficient
H.Merijn Brand (procura
Honored Contributor

Re: change characters

1. All above change *every* occurance of 'yes' to 'no', also in 'abcyesdo'
2. The 'tr' example is plain wrong, because it translates *characters* and not patterns:

lep a5:/pro/tu/lep/4gl/sql 115 > cat | tr 'yes' 'no'
aloha
aloha
yes, I am
nos, I am
no, I'm not
no, I'm not
yyyyy
nnnnn
ebebebe
obobobo
enenene
ononono
lep a5:/pro/tu/lep/4gl/sql 116 >

3. use (a safe re in) perl

perl -pi -e's/\byes\b/no/g' my_file

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn