Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed for string in each file

Status
Not open for further replies.

milage

Programmer
Jul 13, 2001
58
US
Hi,

Say I have a directory of files each with a header which looks like this:

#
# $RCSfile: MF.form,v $
# $Author: david $
# $Revision: 1.46.2.6.2.3.2.4 $
#

I want to extract from each file into a variable the long revision number between "$Revision: " amd " $" at the end of the line.

I assume I want to use sed for this but i'm not sure how and I'd prefer not to have to go into a perl script, however, if that is the only way then just say as I can do it myself.

Cheers

Rob
 
#!/bin/ksh

for file in myFiles*
do
sed -n -e 's/.*\$Revision:[^0-9]*\([0-9.][0-9.]*\).*/\1/p' ${file}
done
vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Rob:

Using sed is the best, most obvious answer, but you can use tr:

var=`egrep &quot;Revision:&quot; file| tr -dc .0123456789`
echo $var

Regards,

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top