|
|
On the subject of perl...
This program is in the "Programming Perl" book, which is far niftier. It allows you to rename file(s) based on matching a regular expression, which in this case would be something like this:
% rename 's/_+/_/g' *.jpgor even something like this to scan all sub-directories: % find . -type f -name '*__*' -print0 | xargs rename 's/_+/_/g'One of the beauties of this program is that the regexp can be a perl regexp, so you can do stuff like 'tr/A-Z/a-z/' to lower-case all file names and so on.
#!/usr/bin/perl
($op = shift) || die "Usage: rename {perlexpr|regexpr} filename [...]n";
if (!@ARGV){
@ARGV = ;
chop(@ARGV);
}
for (@ARGV){
$was = $_;
eval $op;
die $@ if $@;
if($was ne $_){
print "$was -> $_n";
rename($was,$_) unless $was eq $_;
}
}
Enjoy. I appreciate that this is not a good example for people wanting to learn perl, as it is very terse.
cheers
RET
Could such a script scrub duplicate chars in a text file?
Before I try and understand this magic spell you're sharing with us, I want to ask about an idea it's given me.
Could such a script scrub duplicate chars in a text file?
you should definitely keep on at learning scripting, however, for viewing man files why not just install manthor... a cocoa app that automagically loads the man your request in a regular cocoa window, with bookmarks and all. try it. you will like it.
Could such a script scrub duplicate chars in a text file?
You can do what you're asking for within 'man' itself, using syntax similar to that of the vi editor. Here's the help screen you get
Most commands optionally preceded by integer argument k. Defaults in brackets. Star (*) indicates argument becomes new default. ------------------------------------------------------------------------------- <space> Display next k lines of text [current screen size] z Display next k lines of text [current screen size]* <return> Display next k lines of text [1]* d or ctrl-D Scroll k lines [current scroll size, initially 11]* q or Q or <interrupt> Exit from more s Skip forward k lines of text [1] f Skip forward k screenfuls of text [1] b or ctrl-B Skip backwards k screenfuls of text [1] ' Go to place where previous search started = Display current line number /<regular expression> Search for kth occurrence of regular expression [1] n Search for kth occurrence of last r.e [1] !<cmd> or :!<cmd> Execute <cmd> in a subshell v Starts $EDITOR or /usr/bin/vi at current line ctrl-L Redraw screen :n Go to kth next file [1] :p Go to kth previous file [1] :f Display current file name and line number . Repeat previous command ------------------------------------------------------------------------------- This could all be inherited from the current $EDITOR environment variable, and seeing as I haven't currently set $EDITOR it might be defaulting to the 'more' pager command. In other words, if you want to page through files with a different pager then set $EDITOR and the man command will use it instead. *testing...* No, the variable to set seems to be $PAGER, not in this case $EDITOR. So, if you want to use the less command (which has a much richer syntax) and you're using the default tcsh as your shell, then run "setenv PAGER less" to add the variable to your current enviromnent [or put this in a login script so that it works all the time] and then run man again. It should now support more interesting syntax than that offered by, well, 'more'. Sure enough, I test this now as I'm writing, setting less as my $PAGER and then viewing a long manpage, and when I hit 'h' to bring up help I get a different display than what you see above -- much more than can be reasonably pasted into this form. See for yourself if you'd like to try it :-)
Use one of the
I was able to do what you want with the following command:
On the subject of perl...
Here, again, is my slightly better Perl regexp renaming script:
On the subject of perl...
dead link
On the subject of perl...
I wrote my own script to do this and called it 'rn' [since I don't read news using rn any more :-)]. I've put a copy of rn on my mac.com home page. Enjoy.
You use it like this:
% rn P100501 sunday-
if you had files named P1005011.jpg P1005012.jpg P1005013.jpg, you would now have files named "sun-1.jpg", "sun-2.jpg", and "sun-3.jpg".
|
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.05 seconds |
|