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


Click here to return to the 'And yet another way:' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
And yet another way:
Authored by: gidds on Mar 14, '05 10:23:52AM
for FILE in *.txt; do mv $FILE ${FILE%.txt}.rtf; done

This uses a standard shell loop.  The clever bit is the ${FILE%.txt}, which fills in the value of $FILE but strips out any '.txt' suffix from it.  You can also use # instead of % to strip out a prefix instead.

This works in zsh, bash and sh, though not csh.  But, I'm right with the previous poster in thinking that zsh is great and wondering why everyone else isn't using it already!  For example, you can apply this to all .txt in all subdirectories too just by changing the *.txt to **/*.txt.  Neat, huh?

---
Andy/

[ Reply to This | # ]

And yet another way:
Authored by: duelafn on Mar 14, '05 11:23:59AM
You should put double quotes around the variable names:
for FILE in *.txt; do mv "$FILE" "${FILE%.txt}.rtf"; done


[ Reply to This | # ]
And yet another way:
Authored by: LC on Mar 14, '05 08:40:31PM
csh (and tcsh) users --

foreach f (*.txt)
  mv -i ${f} ${f:r}.text
end
csh, tcsh (if you find yourself using it) has those nifty word substitution operators ... Larry.

[ Reply to This | # ]