The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help for a perl script - writing to a data file meghana Shell Programming and Scripting 2 02-04-2008 05:05 PM
Writing CGI scripting using perl alma Shell Programming and Scripting 7 04-23-2007 09:46 PM
Writing and executing a script in RTR implementation of UNIX mahajan.anubhav Shell Programming and Scripting 0 03-16-2006 05:20 AM
Need help in writing a unix script pray44u Shell Programming and Scripting 1 03-30-2005 07:15 AM
Writing perl module jo_aze Shell Programming and Scripting 4 08-06-2003 11:10 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-01-2008
Dinkster Dinkster is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 2
Smile Perl Unix Script Writing

Hi Folks,

I posted a few days ago, thanks for the responses. My original question was for renaming files of sort 3p2325294.dgn in a directory containing multiple files. I need to drop the first 2 characters and the last in a unix script using Perl. How does it differ from using the Unix Shells? Syntax examples please.

Much appreciated.

Dinkster
  #2 (permalink)  
Old 02-01-2008
Lakris Lakris is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 242
Well, if You use the shell You are working in, from the command line or in a script, You are using less resources than You would do if You invoke an external program. You are using functions that are "already there". It's not very important in day to day work if a job takes 10 seconds instead of 2. The trade-off comes into play when You are dealing with very large amounts of data. Perl can be very efficient but if You are only traversing Your home directory for renaming dgn-files, it is probably much easier to just use what You already have. Portability and complexity are other considerations.

Your example could be expressed in a shell (this works for bash on the command line) as:

Code:
for x in *.dng;do mv $x ${x:2};done
meaning, for each file that matches the pattern *.dng, rename it to the same name but cut out the first two characters, or rather, start at character index 2. The index starts from 0, so Your file 3p2325294.dgn would be renamed to 2325294.dgn

I think that once You get used to the shell You realise the power of it. There are so many examples of piping stuff through sed and awk and perl, when the answer is already at Your fingertips. I've done it myself a lot. It may be easier because You know how sed works so You go for it instead of exploring the shell equivalent.

And I'm not entirely sure about how it would be written in Perl, I'm a bit rusty in that department...

/Lakris
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0