Solved

simple question

Posted on 2000-04-27
1
153 Views
Last Modified: 2010-03-05
say that i want to change all pentium into pentiumpro in a file. Then i can do.

#!/usr/bin/perl

while (<>) {
   $_ =~ s/pentium/pentiumpro/g;
   print $_;
}

and run the scriot like ./script.pl oginal-txt > new.txt

But how can I do that at the comandline with perl?

I also wounder how i can replace the word in the orginal txt whitout having to redirect the output to a new file.
0
Comment
Question by:pucko
1 Comment
 
LVL 3

Accepted Solution

by:
monas earned 50 total points
ID: 2759116
perl -i -p -e 's/pentium/pentiumpro/g' file1 file2 file3 and so on

command line switches:
-i make changes "inplace" (actually creating a new file and renaming it to the old one when finished)
-e  code to run
-p run code for every line in the input AND print $_ when code is done.

Hope this helps
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now