Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 3rd January 2009
s0xxx's Avatar
s0xxx s0xxx is offline
Package Pilot
Join Date: May 2008
Posts: 192

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.
[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
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

bre, regular expressions, vils

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cleaning Portsnap files in /var/db/portsnap/files bram85 FreeBSD Ports and Packages 2 5th October 2009 09:54 AM
PHP regular expression help cajunman4life Programming 2 16th August 2008 05:17 PM
How to sync files over ftp graudeejs FreeBSD General 4 4th August 2008 10:18 PM
Mount filesystem with a regular user ivanatora FreeBSD General 15 30th July 2008 08:51 AM
are you an former bsdforum regular? ephemera Off-Topic 18 28th July 2008 12:57 PM

All times are GMT. The time now is 12:22 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick