perl -i -p -e 's/foo/bar/g' test.txt -- Is there any equivalent method in Unix Shell (eq vi, sed, awk ..etc). DON'T GIVE ME THE ANSWER BY USING REDIRECT (> OR >>) TO OTHER FILES.
suhaimi - redirection would be the obvious way to do this, why can't you use that? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
Neil,
The method you give does not work at all....
echo '1,$s/foo/bar/g
w' | ed - test.txt
MikeLacey,
The reason I do not want to use redirect is bcoz it's not practical to use if the file is very huge (>1000 K lines) and processed in for loop...
Suhaimi,
The code worked OK when I tested it. Could you be more specific with the errors you are getting:
(1) is echo in your $PATH
(2) is ed in your $PATH
(3) does your shell allow continutions (ie: 'xxx[return]yyy')
(4) have you remembered the [return] between the subsitute and save command
I still don't understand why you can't use the perl command?
Cheers, Neil
if you are finding and replacing the same number of characters you can open the file in read/write mode with a C program or perl script - you can then scan through the file and write just the data you want into the original file
it's not particuarly easy though - i'd just use the redirect stuff if possible Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.