The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



Thread: Sed Question?
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 02-02-2008
drl's Avatar
drl drl is offline
Registered User
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 580
Hi.

If you are stuck with a sed that does not recognize "-r" such as on Solaris, you can use:
Code:
#!/bin/bash -

# @(#) s1       Demonstrate sed extended regular expression match, substitution.

SED=/usr/xpg4/bin/sed
SED=sed

echo "(Versions displayed with local utility \"version\")"
# version >/dev/null 2>&1 && version =o $(_eat $0 $1) $SED
uname -rs
version >/dev/null 2>&1 && version bash $SED

FILE=${1-data1}
echo
echo " Input file $FILE:"
cat $FILE

echo
echo " As processed by sed:"
# $SED -r -e 's/([0-9]+)-([0-9]+)[ ]*/{\1..\2} /g' $FILE
$SED  -e 's/\([0-9][0-9]*\)-\([0-9][0-9]*\)[ ]*/{\1..\2} /g' $FILE

exit 0
Which yields:
Code:
$ ./s1
(Versions displayed with local utility "version")
SunOS 5.10
GNU bash 3.00.16
sed (local) - no version provided.

 Input file data1:
12-13 15-18 23-28 36-38 42-43 53-56 70-72 76 80-86 93-110 119-128

 As processed by sed:
{12..13} {15..18} {23..28} {36..38} {42..43} {53..56} {70..72} 76 {80..86} {93..110} {119..128}
It seemed to have worked with both versions of Solaris sed ... cheers, drl
Reply With Quote