How do I do this using vi?
I am editing an html file.
I want every line that starts at the leftmost column, with any alpha character, to be bold. I want to go from: Example Line to <b>Example Line</b> I would rather do this with a few simple simple commands, as opposed to one very complex command. |
Would you settle for sed?
Code:
sed 's/^\([[:alpha:]].*\)/<b>\1<\/b>/' file.txt |
You can do something like this:
Quote:
|
Thanks, it worked great.
Would you please explain this to me a little? :1,$s?^[A-Za-z].*?<b>&</b>? I've always done a global substitute like: :%s/oldstring/newstring/g. You seem to use a $ instead of %, and ? instead of /. I'm sure there must be some good reason. Why is there a "1" at the beginning? Could I use [a-Z] instead of [A-Za-z] ? I suppose ^[A-Za-z] means any char at the beginning of the line, and the * means anything that follows. But I don't understand the dot. |
Quote:
For the separator character, you can use almost anything, not just /. I used ?. If the substitution involves a / (as in </b>), it's easier to use something other than a / so you don't have to escape it.[/quote] Quote:
Quote:
By the way, the ampersand (&) means "the thing that was matched". Also take a look at what homey did. |
Great, you are helping a lot. Can you answer just one more?
I have mistakes in the document like this: top<li>secret. I want to replace them with top-secret. I can not do this with: :%s/[A-Za-z]<li>/&-/g or :%s/[A-Za-z]<li>/[A-Za-z]-/g so how do I replace the <li> with a - ? |
If your string is always "top-secret", then you can do something simple like:
Quote:
Quote:
|
All times are GMT -5. The time now is 05:21 PM. |