Click to See Complete Forum and Search --> : i give up
crokett
05-04-2001, 01:07 PM
i need to edit an rpm .spec file to change the release number to the current date, preferably from a single command using
perl -i pe. the problem is i need to search for the pattern 'Release:' and replace what comes after it. all the pattern matching examples i see tells how to find something and replace what you found, not find something and replace the next x chars after it.
the closest i can get is ~/Release:\s(.{x})/ which will allow me to assign the next x chars after Release: to a variable.
thanks
Mikey123
05-04-2001, 01:15 PM
Originally posted by crokett:
<STRONG> find something and replace the next x chars after it.
the closest i can get is ~/Release:\s(.{x})/ which will allow me to assign the next x chars after Release: to a variable.
thanks</STRONG>
=~s/(Release:\s*).{x}/$1yourstuffhere/
this will match Release: followed by 0 or any number of spaces followed by anything x times and replace it with "Release:[spaces matched]yourstuffhere"
YaRness
05-04-2001, 01:19 PM
can you part of the file for an example?
jemfinch
05-04-2001, 03:11 PM
If it's all on one line, then just do this:
s/Release:\s+(.*)/Release: <today's date>/
Let the end of the line determine how much you need to replace.
Jeremy
crokett
05-04-2001, 04:15 PM
thanks for your help.
here is the finished code:
#! /usr/bin/perl
# This program searches the spec file for the date then changes it to update
# the version number
# there is probably a shorter way of doing
# this next date bit, but this works
($day, $month, $year)=(localtime)[3,4,5];
$year=$year-100;
$zed=0;
$month=$month+1;
$month=$zed.$month;
$day=$zed.$day;
$year=$zed.$year
$newDate=$month.$day.$year;
@ARGV="test.spec";
$^I=".bk";
while (<> ){
~s/(Release:\s*).{6}/$1$newDate/;
print;
}
[ 04 May 2001: Message edited by: crokett ]