Sunday, July 24, 2011

FIND and REPLACE TEXT inside a file without using TEXT Editor

FIND and REPLACE TEXT inside a file without using TEXT Editor

You can perform a text replace within a file without using VI or other text editor available on your Unix or Linux box. Below command will help you perform that action. 

Using SED:

Using PERL:

FIND TEXT - Content you want to replace
REPLACE TEXT - New Value of the content


Arun Rahul said...

Thanks for the Perl command dude.
For sed -i option was troubling.

kdp said...

Thanks for the efforts on gathering useful content and sharing here. You can find more question and answers on Unix and Linux in the following forum.

Unix and Linux technical discussion forum

אהרן יפה said...

Hi! Thanks for your post. I have a question:
I'm a student and i have task to replace all instances of "abc" by uppercase.
When I'm using sed command i'm getting just a visually output, and it isn't acctually replacement of the my file's content.
This is the output:
> cat f1
abc Thank You!!!
> sed 's/abc/ABC/g' < f1
ABC Thank You!!!
> cat f1
abc Thank You!!!
And when i'm using this command the file become empty:
sed 's/abc/ABC/g' < f1 >! f1
Sorry about my english and thank you very much,

vasudha dharani said...

Perl online training|Perl training|call us+919000444287 ...
Perl Online Training, Perl Scripting online training by real time Experts from Hyderabad, India. Call 9000444287 for online training demo. Online Perl training ...

Priya Kannan said...

Wonderful bloggers like yourself who would positively reply encouraged me to be more open and engaging in commenting.So know it's helpful.
UNIX Training in Chennai