Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: What one-liners do people actually use?

by jeffa (Chancellor)
on Dec 08, 2005 at 19:21 UTC ( #515345=note: print w/ replies, xml ) Need Help??


in reply to What one-liners do people actually use?

Here is one i used today:

perl -le'for (<*.mas>) {$o=$_;s/mas$/html/; rename $o,$_ }'
I needed to change some .mas extensions to .html extensions.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)


Comment on Re: What one-liners do people actually use?
Download Code
Re: What one-liners do people actually use?
by b10m (Vicar) on Dec 08, 2005 at 19:34 UTC

    You could have just used BASH for this trivial task ;)

    for F in *.mas; do mv $F ${F/.mas/.html}; done

    Update: stupid typo fixed... Thanks jeffa

    --
    b10m

    All code is usually tested, but rarely trusted.

      HERETIC!!! >:(

      Just kidding! ;) I actually did pull off a BASH for loop:

      for i in `ls *.mas`; do tidy -asxhtml -clean -i -wrap 200 $i > $i.new; + done
      And then a Perl one-liner to strip off the .new ... and then i realized that tidy as a -m option to modify the file in place!

      UPDATE: Why Tanktalus? Because you weren't here at the time to show me a better way. :P Thanks for the tips, guys.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      

        Um ... why "ls *.mas" in backticks when you can eliminate the subprocess using just "*.mas"? ;-)

        Also, your renaming ... that's what /usr/bin/rename is for: "rename .mas .html *.mas" ;-)

      Or rename mas html *.mas...

        Correct, like Tanktalus also suggested (half a day before you ;-) The "problem" with that is that you might run into problems if you have a lot of files. At least with running a Linux kernel(not sure with other OSes), you'll run into the 'Argument list too long' error (or you may have tweaked your MAX_ARG_PAGES kernel setting).

        --
        b10m

        All code is usually tested, but rarely trusted.
Re^2: What one-liners do people actually use?
by ikegami (Pope) on Dec 08, 2005 at 20:32 UTC
    You didn't need Perl for that:
    for %q in (*.mas) do ren %q %~nq.html
      ren *.mas *.html

          --k.


        duh! silly me! I've been doing
        for %q in (TESTA.*) do copy %q TESTB%~xq
        a lot lately, so I wasn't thinking straight.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://515345]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2014-08-29 11:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (280 votes), past polls