Maintenance

  • Home
  • Log in
  • « Invoke VM settings for Tomcat
  • Generating font metrics file for FOP in Cocoon »

Code snippet

Posted by gregster on 05 Nov 2008 in R & D, Activity log

I had a bunch of files with duplicate extensions (filename.jpg.jpg) and wanted to trim it to one .jpg so I did this:
ls *.jpg.jpg | awk '{print("mv "$1" "$1)}' | sed 's/.jpg.jpg/.jpg/2'
which just printed the results to stdout. I fiddled with the command until it output what I wanted, then I appended | /bin/sh to get this:
ls *.jpg.jpg | awk '{print("mv "$1" "$1)}' | sed 's/.jpg.jpg/.jpg/2'|/bin/sh
which renamed the files appropriately. Cool.

Something similar can be accomplished thusly:
find . -iname "*pattern1*" -exec echo "mv '{}' '{}'" \; | sed 's/pattern2/pattern3/2' | /bin/sh
where: pattern1 is the mask that select which files to process; pattern2 is the string to be modified; and pattern3 is the substitution for pattern2 (leave empty for deletion)

This entry was posted by Greg and filed under R & D, Activity log.

Maintenance

This blog is the location for all work involving software and hardware maintenance, updates, installs, etc., both routine and urgent.
  • Home
  • Recently
  • Archives
  • Categories

Search

Categories

  • All
  • Announcements
  • Hit by a bus
  • Labs
    • Activity log
    • Documentation
  • Notes
  • R & D
    • Activity log
    • Documentation
  • Servers
    • Activity log
    • Documentation
  • Tasks

All blogs

  • Academic
  • AdaptiveDB
  • Admin
  • Announcements
  • CanMys
  • Cascade
  • CGWP
  • ColDesp
  • Depts
  • DVPP
  • Endings
  • HCMC Blogs
  • Landscapes
  • LEMDO
  • Linguistics
  • Maint
  • LondonMap
  • Mariage
  • MoM
  • Moses
  • Pro-D
  • Projects
  • ScanCan
  • HumsSites
  • Wendat

This collection ©2022 by admin • Help • PHP framework