0

I have files like

update-1.0.1.patch
update-1.0.2.patch
update-1.0.3.patch
update-1.0.4.patch
update-1.0.5.patch

And I have a variable that contains the last applied path (e.g. update-1.0.3.patch). So, now I have to get a list of files to apply (in the example updates 1.0.4 and 1.0.5). How can I get such list?

To clarify, I need a method to get a list of files that comes alphabetically later of given file and this list of files must be also in alphabetical order (obviously is not allways possible to apply the patch 1.0.5 before 1.0.4).

1 Answer 1

2

sed is your go-to guy for printing ranges of lines. You give it a starting/ending address or pattern and command to do between.

ls update-1.0.* | sort | sed -ne "/$ENVVAR/,// p"

The sort probably isn't necessary because ls can sort by name, but it might be good to include as a courtesy to maintainers to show the necessity. The -n to sed means "don't print every line automatically" and the -e means "I'm giving you a script on the command line". I used " to enclose the script to that $ENVVAR would be eval'd. The ending address is empty (//) and the p means "print the line".

Oh, and I just noticed you only want the ones later. There's probably a way to tell sed to start on the line after your address, but instead I'd pipe it through tail -n +2 to start on the second line.

2
  • Great, only one problem. This returns also the $ENVVAR content, in my example update-1.0.3 that was already applied. How can get rid of this first update? Thanks!
    – Ivan
    Commented Nov 11, 2011 at 12:12
  • I edited the answer to fix that. Add a pipe on the end through tail. Or read the manual on sed to figure out how to add 1 to the address....
    – drysdam
    Commented Nov 11, 2011 at 12:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.