Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Find latest version from file name and increment the version

Posted on 2014-04-04
5
Medium Priority
?
524 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 total points
ID: 39983871
open F,">V".((sort{$a<=>$b}map{/(\d+)/}<V*__$sometext4.sql>)[-1]+1)."__$sometext4.sql";
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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 how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.
Suggested Courses

719 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