ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Hi, I am playing with sed and was trying the following command:
less hwl | sed 's/[Tt]h*/((&))/'
I would think it will only put (( )) around instances of Th... and th....,
but it also put paranthesis around t... and T....
Madame Sosos((t))ris, famous clairvoyante,
Had a bad cold, never((th))eless
Is known ((t))o be the wisest woman in Europe,
Wi((th)) a wicked pack of cards. Here, said she,
Is your card, ((th))e drowned Phoenician Sailor,
(((Th))ose are pearls that were his eyes. Look!)
Here is Belladonna, ((th))e Lady of the Rocks,
((Th))e lady of situations. 50
Here is ((th))e man with three staves, and here the Wheel,
And here is ((th))e one-eyed merchant, and this card,
Which is blank, is some((th))ing he carries on his back,
Which I am forbidden ((t))o see. I do not find
((Th))e Hanged Man. Fear death by water.
I see crowds of people, walking round in a ring.
((Th))ank you. If you see dear Mrs. Equitone,
((T))ell her I bring the horoscope myself:
One mus((t)) be so careful these days.
I thought it needs to be th or Th to meet the condition, not t or T on its own.
You should remove the "*" as it substitutes 0 or more instances of h, so Th, th, t, and T will be substituted.
I'd also put the "g" option at the end of the sed expression otherwise only the first occurrence on the line of the buffer will be substituted.
ie the last line of your file has two occurences of the buffer, but only one is substituted
One mus((t)) be so careful ||th||ese days.
The problem is the asterisk: it means that the preceding regular expression should be repeated as many times as necessary to find a match, that is your regex will match any occurrence of 'T' or 't', followed by any number of 'h'. Including zero.
Just remove the asterisk and it will work in the expected way:
here I also added the g specifier to match the multiple occurrences on the same line (as in the 6th one of your example).
Edit: sorry for redundancy... I did not see your post, urka58 before posting mine.