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 -->
  #4 (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.

The seds I have used do not do "in-place" processing by default. If they allow it, it's usually with the "-i" option.

If your sed allows "-r", here's one way:
Code:
#!/bin/bash -

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

echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version =o $(_eat $0 $1) 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

exit 0
Producing:
Code:
% ./s1
(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash 2.05b.0
GNU sed version 4.1.2

 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}
See man sed for details ... cheers, drl

Last edited by drl; 02-02-2008 at 05:01 PM.. Reason: Spelling mistake.
Reply With Quote