The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM
Home Forums Register Rules & FAQ Members List Arcade Search Today's Posts Mark Forums Read


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 !!


Other UNIX.COM Threads 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 01:05 PM
Writing CGI scripting using perl alma Shell Programming and Scripting 7 04-23-2007 06:46 PM
Writing and executing a script in RTR implementation of UNIX mahajan.anubhav Shell Programming and Scripting 0 03-16-2006 01:20 AM
Need help in writing a unix script pray44u Shell Programming and Scripting 1 03-30-2005 04:15 AM
Writing perl module jo_aze Shell Programming and Scripting 4 08-06-2003 08:10 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-01-2008
Registered User
 

Join Date: Jan 2008
Posts: 2
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-01-2008
Registered User
 

Join Date: Oct 2007
Posts: 75
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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
Reply With Quote
Google UNIX.COM
Reply



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB 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 -7. The time now is 07:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102