View Single Post
Old 3rd January 2009
s0xxx's Avatar
s0xxx s0xxx is offline
Package Pilot
 
Join Date: May 2008
Posts: 192
Default

Quote:
Originally Posted by J65nko View Post
The input was a list of files, the output should be mv commands to rename the files. The sed solution is a little bit complicated, because there is no easy way to save the original file name.
Code:
[soxxx@bsd test]$ ls lat* | sed 's/\(.*\)/mv & &/; s/-/_/; s/\(.*\) \(.*\) \(.*\)/\1 \3 \2/'
mv latest-pkg latest_pkg
mv latest-pkg-calyx latest_pkg-calyx
mv latest-pkg-esat latest_pkg-esat
mv latest-pkg-plig latest_pkg-plig
[soxxx@bsd test]$ ls lat* | sed 's/\(.*\)/mv & &/; s/-/_/; s/\(.*\) \(.*\) \(.*\)/\1 \3 \2/' | sh
[soxxx@bsd test]$ ls
latest_pkg  latest_pkg-calyx  latest_pkg-esat  latest_pkg-plig
Quote:
Originally Posted by J65nko View Post
Your one-liner does not create these 'mv' commands files, as was the requirement
Right, I wasn't thinking about 'mv' command at all!
__________________
The best way to learn UNIX is to play with it, and the harder you play, the more you learn.
If you play hard enough, you'll break something for sure, and having to fix a badly broken system is arguably the fastest way of all to learn. -Michael Lucas, AbsoluteBSD
Reply With Quote