Solved

Find latest version from file name and increment the version

Posted on 2014-04-04
5
522 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 500 total points
ID: 39983871
open F,">V".((sort{$a<=>$b}map{/(\d+)/}<V*__$sometext4.sql>)[-1]+1)."__$sometext4.sql";
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SMTP log file for IMSVA 5 75
Archiving and Removal of old files AIX 7.1 2 31
bash: ./Facebooker.pl :Permission Denied 9 58
PartedMagic Secure Erase 14 33
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

752 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