Solved

Find latest version from file name and increment the version

Posted on 2014-04-04
5
523 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

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…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.
Suggested Courses

627 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