daggerquill said: > On Mon, 22 Nov 2004 08:56:59 +0000, Gavin Henry <[EMAIL PROTECTED]> wrote: >> Hi all, >> >> I have a log file a like this: >> >> The following packages were available in this version but NOT upgraded: >> Canna-devel-3.7p3-6.i386.rpm >> GConf-devel-1.0.9-15.i386.rpm >> Guppi-devel-0.40.3-21.i386.rpm >> HelixPlayer-1.0.1.gold-6.i386.rpm >> Maelstrom-3.0.6-6.i386.rpm >> MagicPoint-1.11b-1.i386.rpm >> NetworkManager-0.3.1-3.i386.rpm >> NetworkManager-gnome-0.3.1-3.i386.rpm >> >> But with many more lines. I want to create a regex or substition to get >> rid of >> the rpm numbering and leave only the package name, so I can feed this to >> apt >> or yum and install the missing rpms. >> >> So far I have swapped all \n for spaces, which gets everything on one >> line >> (using perl on the command line perl -pi -e 's/\n/ /' toinstall.log) >> >> Can I make a regex for this, (don't tell me how, I'm just not sure which >> way >> to go) or should I carry one with substition? >> >> Also, could I match rpm and substitute so many characters in front of it >> as >> well, like match rpm + 7 chars? >> >> Gavin. > > Gavin, > > Substitutions are regexes. The question is just whether to look for > what you want to get rid of (s///), or what you want to keep (m//). I > would say that in most cases, it's going to be easier to look for what > you don't want (.+i386.rpm) than to figure out the various forms what > you do want might take, and building the memory parenthesis > accordingly (or using $'). I'd personally go with something like > 's/-.+?.rpm//'.
ah, great. > > If you're looking at a very large file, and you know you want to strip > a fixed number of characters from the end of every line (e.g. just > remove the 'i386.rpm' and leave all of the version numbers), you could > speed things up by using substr(). The file is the upgrade.log from upgrading FC2 to FC3 (Fedora Core) and is about 55,000 lines long due to xml docs errors. But the sed/grep command from Chris took about 1/2 a second to parse it :-) -- Just getting into the best language ever... Fancy a [EMAIL PROTECTED] Just ask!!! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>