Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Find latest version from file name and increment the version

Posted on 2014-04-04
5
Medium Priority
?
525 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 85

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 85

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 85

Accepted Solution

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

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month13 days, 2 hours left to enroll

972 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