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:
sed -i 's/FIND TEXT/REPLACE TEXT/g' FILENAME.TXT


Using PERL:
perl -p -i -e "s/FIND TEXT/REPLACE TEXT/g" FILENAME.TXT




Where:
FIND TEXT - Content you want to replace
REPLACE TEXT - New Value of the content
FILENAME.TXT - Filename

17 comments:

Arun Rahul said...

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

Unknown 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,
Roni

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

nilashri said...

Read all the information that i've given in above article. It'll give u the whole idea about it.

Data Science training in chennai
Data science training in velachery
Data science training in tambaram
Data Science training in OMR
Data Science training in anna nagar
Data Science training in chennai
Data science training in Bangalore
Data Science training in marathahalli

simbu said...

It is better to engaged ourselves in activities we like. I liked the post. Thanks for sharing.
java training in chennai | java training in bangalore

java online training | java training in pune

selenium training in chennai

selenium training in bangalore

gowsalya said...

Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.
Devops training in marathahalli
Devops training in rajajinagar

Ram Ramky said...


Great blog, keep posting and update more information.

Selenium training in Chennai
Selenium Courses in Chennai
best ios training in chennai
Digital Marketing Training in Chennai
JAVA J2EE Training Institutes in Chennai
.Net coaching centre in chennai
.Net course in chennai
mvc training in chennai
Big Data Training in Chennai

easylearn said...

Hi,
Good job & thank you very much for the new information, i learned something new. Very well written. It was sooo good to read and usefull to improve knowledge. Who want to learn this information most helpful. One who wanted to learn this technology IT employees will always suggest you take python training in bangalore. Because Python course in Bangalore is one of the best that one can do while choosing the course.

gautham said...

Your post is awesome business analyst online course

nizam said...

this post is great to learn many things
BEST ANGULAR JS TRAINING IN CHENNAI WITH PLACEMENT

https://www.acte.in/angular-js-training-in-chennai
https://www.acte.in/angular-js-training-in-annanagar
https://www.acte.in/angular-js-training-in-omr
https://www.acte.in/angular-js-training-in-porur
https://www.acte.in/angular-js-training-in-tambaram
https://www.acte.in/angular-js-training-in-velachery

nizam said...

Thanks for sharing this useful content.
AngularJS training in chennai | AngularJS training in anna nagar | AngularJS training in omr | AngularJS training in porur | AngularJS training in tambaram | AngularJS training in velachery


vivekvedha said...

"It is really a great and useful piece of information
Digital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery

"

aarthi said...

Thanks for giving the knowledge about the text editor.
Java training in Chennai

Java training in Bangalore

Java training in Hyderabad

Java Training in Coimbatore

Java Online Training

Cyber Security said...

Very interesting blog. Many blogs I see these days do not really provide anything that attracts others, but believe me the way you interact is literally awesome.You can also check my articles as well.

360DigiTMG Data Science Course In Pune

Thank you..

ganesh said...

Informative post indeed, I’ve being in and out reading posts regularly and I see alot of engaging people sharing things and majority of the shared information is very valuable and so, here’s my fine read.
Angular js Training in Chennai

Angular js Training in Velachery

Angular js Training in Tambaram

Angular js Training in Porur

Angular js Training in Omr

Angular js Training in Annanagar

Pushba said...

Great efforts put to publish these kinds of articles that are very useful to know. I’m thoroughly enjoying your blog. And Good comments create great relations. You’re doing an excellent job. Keep it up.
IELTS Coaching in chennai

German Classes in Chennai

GRE Coaching Classes in Chennai

TOEFL Coaching in Chennai

Spoken english classes in chennai | Communication training

VISWA Technologies said...

I value the blog post. Really looking forward to reading more.
Big Data Hadoop Training
<a href="https://viswaonlinetrainings.com/courses/react-js-online-training/>React JS Training</a>