> Tryig to help a lister on another group rename a few thousand
> files. As the last step I need to line number a text file but then move
> the line number to the end of each line. In other words go from lines
> like
>
> 1234 mv oldfilenane newprefix
> to
> mv oldfilename newprefix1234
>
> Adding the suffix in a subsequent step is trivial:
> :%s/$/.jpg/
Well, the entire process (including the initial numbering) could
be done in one step:
:%s/$/\=submatch(0).line('.').'.jpg'
which will append both the line# and the .jpg extension.
However, if you must move pre-existing line-numbers to the end,
I'd recommend
:%s/^\(\d\+\)\s*\(.*\)/\2\1.jpg
If you want to do it purely on the command-line, assuming
files.txt has the lines "mv oldfilename newprefix" in it, you can use
sed -n 'p;=' numbers.txt | sed 'N;s/\n//;s/$/.jpg/'
to number the lines, then move the line numbers up a line and
append the .jpg extension. The entire result, if it meets your
approval can then just be piped to a shell to execute them:
sed -n 'p;=' numbers.txt | sed 'N;s/\n//;s/$/.jpg/' |sh
Hope this gives you some options,
-tim
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment