This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Cygwin's vanilla sed : capabilities and limitations


> -----Original Message-----
> From: fergus@bonhard.uklinux.net [mailto:fergus@bonhard.uklinux.net]
> 
> Q1. Querying info sed reveals the expression matcher to be "greedy",
> matching the longest possible string. Is there a way to make 
> it match the
> shortest possible, so that echo aaabbbccc | sed 's/^.*b//' 
> (altered but
> similar) grabs aaab not aaabbb?

echo aaabbbccc | sed 's/^[^b]*b//'

but that actually replaces 'aaab' with '', leaving 'bbccc'

echo aaabbbccc | sed 's/b.*$/b/'

will leave you with 'aaab'.

> Q2. Is there a way using the supplied sed without major 
> enhancements to
> change "abc x def" to "def x abc": that is, to grab two 
> distinct portions
> and swap them (using $1,$2 or \1,\2 or whatever).

echo abc x def | sed 's/\(.*\) x \(.*\)/\2 x \1/'

will do the job. Replace the '.*'s with REs that match the side expressions,
and ' x ' with an expression matching your delimiter.

Enjoy

Dave.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]