Find and replace permanently


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and replace permanently
# 1  
Old 03-04-2009
Find and replace permanently

i have a few scripts in which i need to find string"ali1@abcd.com" and replace it with "ali@abcd.com"
i used 2 below commands but none of them is permanently replacing the old string in the script s.sh

Code:
perl -pi -e 's/ali1@abcd.com/ali@abcd.com/g' s.sh

sed 's/ali1@abcd.com/ali@abcd.com/g' s.sh

Please help me in this
# 2  
Old 03-04-2009
Try this

for line in `cat /dir/s.sh`
do
echo $line >file.sh
sed 's/ali1@abcd.com/ali@abcd.com/g' file.sh >>output.sh
done
mv output.sh s.sh

or

sed 's/ali1@abcd.com/ali@abcd.com/g' s.sh>s1.sh
mv s1.sh s.sh
# 3  
Old 03-04-2009
Try escaping the @ symbols. The dots should be escaped also, otherwise they actually stand for "any single character".

perl -pi -e 's/ali1\@abcd\.com/ali\@abcd\.com/g' s.sh
# 4  
Old 03-04-2009
i cannot do the rename part as most of the scripts after renaming i need to change the permission.

As i m working in production enviroment so i just want the command which can just overwrite the scripts rahther than renaming it.
# 5  
Old 03-04-2009
Check if this works for you..

Code:
sed -i -e's/ali1@abcd.com/ali@abcd.com/g;' s.sh

# 6  
Old 03-04-2009
No. it's telling the below error:
Code:
sed -i -e's/ali1@abcd.com/ali@abcd.com/g;' s.sh

sed: illegal option -- i
Usage:  sed [-n] Script [File ...]
        sed [-n] [-e Script] ... [-f Script_file] ... [File ...]

# 7  
Old 03-04-2009
Hi Ali ,
Though the above version is working fine for me you can try
sed -e's/SEARCH/REPLACE/g;' asd_dup.txt
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Set autolist permanently

Hi , How to set autolist permanently in Solaris 10 (2 Replies)
Discussion started by: ankit.padhiyar
2 Replies

2. Red Hat

Change service name permanently

Hi, Since everything is doable in Linux so far, what is the ability of changing a spicifc service name permanently. e.g. I want to change the network service name to connection, so I can use chkconfig command as follow: chkconfig connection off --level 5 # for disabling network service in... (7 Replies)
Discussion started by: leo_ultra_leo
7 Replies

3. UNIX for Advanced & Expert Users

gmail revert to old look permanently

I thought I would share gmail revert to old look permanently. I am sure I am not the only one annoyed by the new look. Install Stylish extension Choose the Stylish UserStyle that you want. I know The Return of Old Gmail and gmail-b2b both work but I prefer gmail-b2b since I think it looks... (0 Replies)
Discussion started by: cokedude
0 Replies

4. UNIX for Dummies Questions & Answers

Replace 8th and 9th characters in file permanently

Good evening, I have a file and wish to replace the 8th and 9th characters on the first line only no matter what they are with 44 and the file permanantly changed. e.g. file example.txt before change: 123456789123456 hi how are you blah blah file example.txt after change: ... (4 Replies)
Discussion started by: GarciasMuffin
4 Replies

5. Solaris

delete routing permanently

How can I remove permanently a route from the routing table? I have the following: root@aiwutr1>netstat -rnv IRE Table: IPv4 Destination Mask Gateway Device Mxfrg Rtt Ref Flg Out In/Fwd -------------------- --------------- --------------------... (3 Replies)
Discussion started by: gianluca.p
3 Replies

6. IP Networking

Changing the Ip adress permanently

well i'm trying to change the ip adress on an old alphaserver runing tru64 4.0F using the ifconfig hme0 IP_ADDRESS mask MASK broadcast BROADCAST and when i check it using ifconfig -a it shows the new ip and all is well but when the server is rebooted it reverts back to the old ip (3 Replies)
Discussion started by: randUSR()
3 Replies

7. UNIX for Dummies Questions & Answers

Change IP permanently without Yast?

Folks; i have a SUSE 10 box and i need to change the IP/GW & Netmask on it but without Yast tool. Which files/services needed to be edited or restarted to make it happen? Thanks in advance (1 Reply)
Discussion started by: Katkota
1 Replies

8. UNIX for Dummies Questions & Answers

numbers on permanently through .bash_profile

Hi Can anyone tell me if it is at all possible to edit ones .bash_profile, to make the setting on of line numbers (in vi/vim), permanent? I've been to a few IRC channels and people keep telling me it is more of a vi/vim thing and to use something called ".vimrc", however I heard that it is... (3 Replies)
Discussion started by: zorrokan
3 Replies

9. UNIX for Dummies Questions & Answers

Turning off MMDF permanently

This is definitely a post from a "UNIX Newbie" - we have a SCO Unix machine that houses our customer database. I have been getting reports that the system starts lagging intermittently, and have managed to determine that the cause of the slowdown is a process called MMDF. I can manually kill... (4 Replies)
Discussion started by: QmanV2
4 Replies

10. UNIX for Dummies Questions & Answers

Unmounting /home Permanently

Hi! I got tired of running out of disk space on the different partitions on my Solaris 8 Ultra 5 computer so I tried to make just a big / partition and install everything on that. But somehow I managed to get a 0 byte /home partition :-) I tried to delete this (By just clicking it in X-Windows and... (8 Replies)
Discussion started by: alfabetman
8 Replies
Login or Register to Ask a Question