Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Linux Shells and Utilities Ten Neat Tricks With Perl Tutorial

Automate redundant repetitive tasks with Perl, using these ten neat tricks!

Tutorial Details:

Linux Shells and Utilities Ten Neat Tricks With Perl

When I am using a computer to do a job I often think 'I am repeating tasks...time to write a script'. Under Linux there are a number of programming systems for scripts. Below we will look at one of them, Perl. Perl is a full blown programming language, but it's good for making short, quickly written programs like scripts. This is because it has a rich set of features and also a wide range of add-on libraries.

Here are ten one liners in perl, illustrating the kinds of task one would use a script for under linux. All the scripts take some kind of argument after the final ' quote that signals the end of the program.

1. perl -p -i -e 's/this/that/g' filename
Search and replace the string 'this' with the string 'that' in the file filename. You can also say * or *.html or any valid wildcard expression instead of filename. The s/// command uses regular expressions. If you want to alter the 'this' and 'that', it's best to avoid .*?[]{}$^ and other odd characters which act as metacharacters in regular expressions. Or better still look at the perlre documentation page. You can do this by saying perldoc perlre . Perl has extensive online documentation, try perldoc perltoc for a list.

2. perl -e 'for (@ARGV) { rename $_, lc($_) unless -e lc($_); }' *
Rename all the files in the current directory to lower case. The $_ is a sort of 'default' variable which is widely used in Perl.


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Linux Shells and Utilities Ten Neat Tricks With Perl Tutorial

View Tutorial:
Linux Shells and Utilities Ten Neat Tricks With Perl Tutorial

Related Tutorials:

Java Q&A - Java Still Open
Java Q&A - Java Still Open
 
The Volano Report: Which Java platform is fastest, most scalable? A JavaWorld exclusive! - JavaWorld - Mar
The Volano Report: Which Java platform is fastest, most scalable? A JavaWorld exclusive! - JavaWorld - March 1999
 
Matchmaking with regular expressions - JavaWorld July 2001
Matchmaking with regular expressions - JavaWorld July 2001
 
Concurrency in JDK 5.0
Concurrency in JDK 5.0 JDK 5.0 added major new support for developing concurrent applications, including JVM changes, new low-level synchronization utilities, and higher-level, thread-safe, high-performance concurrency classes such as thread pools, concu
 
Beginner Guide to Linux Server
Beginner Guide to Linux Server Beginner Guide to Linux Server Introduction Linux is know for its security, performance, reliability. Many business units are looking towards Linux as it provides low costs software for them. Earlier Linux used to
 
Beginner Guide to Linux Server
Beginner Guide to Linux Server Beginner Guide to Linux Server Introduction Linux is know for its security, performance, reliability. Many business units are looking towards Linux as it provides low costs software for them. Earlier Linux used to
 
Buy Fedora Core 3 Linux CD's in India.
Buy Fedora Core 3 Linux CD's in India. Fedora Core 3 Linux Now Available Fedora Core 3 CD's We are providing the free downloadable version of Fedora Core 3 Linux CDs, which is distributed under GNU public license. ABOUT FEDORA Fedora is the
 
We are providing Linux CD's for free.
We are providing Linux CD's for free. Linux! Linux! Linux! The Best Place to get your Free Linux CD's Get Your Linux CD's Today Result of 14-Jan-2003 Red Hat 8.0 Free CD Contest What is Linux? Linux is a free Operating System, Which was
 
Free Linux Distribution in India
Free Linux Distribution in India Free Linux Distribution in India Your premium place to get Free Linux CDs in India Popularity of Linux is growing in World including India. So to be part of this we have decided to help Indian community in getting
 
We are providing Knoppix 3.6 Live Linux CD's
We are providing Knoppix 3.6 Live Linux CD's Knoppix Linux CD's Now Available Linux Knoppix 3.6 CD's What is KNOPPIX? KNOPPIX is a bootable Linux CD with a collection of various GNU/Linux software. It auto-detects hardware and supports many
 
We are providing Knoppix 3.7 Live Linux CD's
We are providing Knoppix 3.7 Live Linux CD's Knoppix Linux CD's Now Available Linux Knoppix 3.7 CD's What is KNOPPIX? KNOPPIX is a bootable Linux CD with a collection of various GNU/Linux software. It auto-detects hardware and supports many
 
We are providing Downloadable Version of Mandrake 10.1 Official Edition Linux CD's.
We are providing Downloadable Version of Mandrake 10.1 Official Edition Linux CD's. Mandrake 10.1 Official Edition Linux Now Available Mandrake 10.1 Official Edition CD's Mandrakelinux 10.1 Official is a new-generation Linux operating system for
 
We are providing Downloadable Version of Mandrake 10.1 Power Pack Linux CD's.
We are providing Downloadable Version of Mandrake 10.1 Power Pack Linux CD's. Mandrake 10.1 Power Pack Linux Now Available Mandrake 10.1 Power Pack CD's Power Pack is a Linux system that will appeal to all advanced users. It's great for Office
 
TheOpenCD is a collection of high quality Free and Open Source Software
TheOpenCD is a collection of high quality Free and Open Source Software TheOpenCD v2.0 Now Available TheOpenCD v2.0 TheOpenCD is a collection of high quality Free and Open Source Software. The programs run in Windows and cover the most common
 
Buy Peanut 9.6 Linux in India from us. Peanut 9.6 distribution is available in India.
Buy Peanut 9.6 Linux in India from us. Peanut 9.6 distribution is available in India. Peanut 9.6 Linux Now Available Peanut 9.6 Linux CD It is a Linux OS (operating system), especially made for those new to Linux. This is the most POWERFUL and
 
We are providing Linux CD's for free.
We are providing Linux CD's for free. Linux 9.0 Linux! Linux! Linux! Get Your Linux CD's Today What is Linux? Linux is a free Operating System, Which was developed by Linus Trovalds to provide free, open source Unix-like OS. The code for Linux
 
Buy SuSe 9.1 Personal CDs in India from us. Suse 9.1 Personal is available with us.
Buy SuSe 9.1 Personal CDs in India from us. Suse 9.1 Personal is available with us. SuSe 9.1 Personal Linux Now Available SuSe 9.1 Personal CD's SuSE 9.1 Personal Edition was based on the x86 port of the Personal Edition, and it includes all of
 
Installing Sun JDK on Linux
Installing Sun JDK on Linux Installing Sun JDK on Linux (Fedora Core 3) Downloading Download the latest version of JDK from http://www.java.sun.com . I have downloaded jdk-1_5_0_01-linux-i586.bin for this tutorial. Installing Change to the
 
What is Web Hosting
What is Web Hosting What is Web Hosting? What is Web Hosting? If you have a company and want web presence than you need a website. With the website any one from the world must be able to view your pages, images etc. Website is actually a
 
Urchin RSS Aggregator
Urchin is a Web based, customisable, RSS aggregator and filter. It\'s primary purpose is to allow the generation of new RSS feeds by running queries against the collection of items in the Urchin database.
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.