shell - BASH: Find highest numbered filename in a directory where names start with digits (ls, sed) -
I have a directory with those files that look like this:
001_something .php 002_something_else Php 004_xyz.php 005_do_good_to_others.php
I would eventually like to create a new, empty PHP file whose name starts with the next number in the series.
LIST = 'exec ls $ MY_DIR | Sed 's / \ ([0- 9] \ + \). * / \ 1 / g '| The previous code gives me a string like this: LIST = '001 002 004 005'
>
< P> I want to capture that 005, the rise of one, and then how can I do this in the bash to create a new file name to use that number < Div class = "post-text" itemprop = "text">
$ list = ($ LIST) $ newfile = 'printf% 03d-whatever $ ($ 10 $ $ {LIST [$ {# LIST} }} + 1)) $ $ resonance $ new file 006-whatever
then, specific. Below is a any-posix-shell-cum-bash solution, but I think that's something simple possible.
$ cat / tmp / zf () {eval echo \ $ {$ #} | Sed -e 's / ^ 0 * //'} LIST = '001 002 004 005' new name = 'printf% 03d-whatever $ (($ (f $ LIST) + 1) `$ newname $ sh / tmp Echo / Z 006- whatever $
Comments
Post a Comment