Quote:
Originally Posted by J65nko
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
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
|