Solved

Find latest version from file name and increment the version

Posted on 2014-04-04
5
517 Views
Last Modified: 2014-04-08
I have a directory called project and subdirectory called migration

the migraton folder has several sql files  in format  V1__Build.sql, V2__Build.sql , V3__Build.sql.

Format  is  V<#><Double Underscore>Build.sql


I want  a script which can sort through the filenames in migration directory and create a  .sql fle with incremented verson number. For example if the directory contains V1__Build.sql, V2__Build.sql and V3__build.sql , script should create V4__Build.sql


thanks for your help
0
Comment
Question by:maverickxx
  • 3
  • 2
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 39979680
perl -e 'open F,">V".((sort{$a<=>$b}map{/(\d+)/}<V*__Build.sql>)[-1]+1)."__Build.sql"'
0
 

Author Comment

by:maverickxx
ID: 39983721
Ozo,
thanks for the reply,

how do  change this perl if the files are in format V1__<sometext1>.sql,  V2__<Sometext2>.sql
0
 
LVL 84

Expert Comment

by:ozo
ID: 39983831
Is <sometext1> different from <Sometext2>?  
Is <Sometext2> the result of capitalizing and incrementing <sometext1>?
Could it be possible to find V1__<Sometext2>.sql,  V2__<sometext1>.sql in the folder?
and if so, what should be done with them?
0
 

Author Comment

by:maverickxx
ID: 39983859
Sometest1 and sometext2 are not changed and are different.  I Just need to extract V# from V#___<sometext>.sql and find the next version.

For simplicity,  lets us asssume that "sometext4" for V4_<sometext4> is coming from a variable $sometext4 from within the script.


So next version would be V4__$sometext4
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 39983871
open F,">V".((sort{$a<=>$b}map{/(\d+)/}<V*__$sometext4.sql>)[-1]+1)."__$sometext4.sql";
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now