Re: sed/regex question.. missing something simple...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Saturday, May 27, 2017 5:27:46 PM EDT bruce wrote:
> Hi.
> 
> I've got a file.. with a bunch of lines looking like:
> 
>   $bookVariable['asu']['Fall-2016']='link';
>   $bookVariable['lehmancuny']['Fall-2016']='1';
>   $bookVariable['uvu']['Fall-2016']='1';
>   $bookVariable['wmich']['Summer II 2017']='1';
>   $bookVariable['wmich']['Summer I 2017']='1';
>   $bookVariable['dmacc']['Summer-2017']='1';
>   $bookVariable['sdmesa']['Summer-2017']='link';
> 
> I''m looking to get the "text" inside the 1st group of brackets []
> 
> The following sed only gets the 1st 3 lines.. and it doesn't
> completely work.
> 
> sed -n "s/^.*bookVariable\['\(\S*\)'].*$/\1/p"  foo.txt

That's because the * quantifier is "greedy" and will match as much as
it can before forcing a match on "'"[1].

The \(\S*\) isn't what you want.  What you probably meant was
\([^']*\) instead.  That will match only the part up to the *first*
closing single quote character.


____________________
[1] The matching will go all the way to the end of the line and then
fail because there's no single quote there.  The matching engine will
start backtracking to the first point that it can get a match of "']".
That will encompass what you are seeing instead of only the first
thingy in the square brackets.  Greedy matching.

-- 
Garry T. Williams
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux