Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Method I often use' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Method I often use
Authored by: victory on Mar 16, '05 06:22:53PM
is this:

ls *.txt | sed -e 's/.*/mv -n "&" "&"/' -e 's/.txt$/.rtf/' | /bin/sh

which is partially based on techniques I've seen here on macosxhints before. A few notes:

  • The doublequotes around the "&"s allows the script to properly handle filenames that may have spaces in them without worrying about escape characters.
  • The mv -n guarantees that mv won't overwrite any existing files with the same target filename (i.e. causes mv file.txt file.pdf to fail if file.pdf already exists. Otherwise mv indescriminately overwrites the file)
  • It's easy to 'preview' the effects of the function above, by simply leaving off the final pipe | /bin/sh which will just print the intended results. A nice way to tell ahead of time what the command will do.


[ Reply to This | # ]