in reply to Re: search and using first letter of words on a line
in thread search and using first letter of words on a line

<quote>I'm having trouble groking how this helps:

<font size="-1><a href="#PINPAORToc" name="PINPAORTxt" style=text-decoration:none">... The font size leaves me puzzled on two counts:</quote>

I really appreciate the help and actually I have some things to look at to help makes things leaner for sure. But my question, the only thing I really need answered ATM is:
How can I extract the first letter from each word in a string and join them together?
I have been searching and it looks like perhaps using perl I need to use the substr, split, and join functions, so if anyone might be able to provide some sort of example I would be grateful.
It seems like it might be a similar request to extracting the first letter of names in a generated list or file?

I am uncertain if a sed example might help but something I have tried in sed is:

sed -ri 's/<b>([A-Za-z])([A-Za-z:,]{0,20})[ ]{0,1}([A-Za-z]{0,1})[ ]{0,1}([A-Za-z:,]{0,20})[ ]{0,1}([A-Za-z]{0,1})[ ]{0,1}([A-Za-z:,]{0,20})[ ]{0,1}([A-Za-z]{0,1})(.*)<\/b>/<font size="-1"><a href="#\1\3\5\7Toc" name="\1\3\5\7Txt" style="text-decoration:none">\1 \2 \3 \4 \5 \6 \7 \8<\/a><\/font><br>/' 1.html

which is getting a little unruly not to mention I am limited to capturing on the first letters of the first four words in the string because sed only has nine memory buffers to recall from, so I think by turning to perl I will give myself a lot more options to do what I want.

cheers nap

Replies are listed 'Best First'.
Re^3: search and using first letter of words on a line
by ww (Archbishop) on Sep 23, 2011 at 10:39 UTC
    For what you're defining as your "need ...ATM," is there some problem with the solution offered in Re: search and using first letter of words on a line? It works:
    #!/usr/bin/perl use strict; use warnings; # 927275 use 5.012; my @title = ("Part II: Nietzsche's Project, An Overall Review", "Learn +ing Perl, 5th Ed.", "Mastering Regular Expressions"); for my $title(@title) { my $acronym = join '', ($title =~ /(?:^|\s+)(\w)/g); say $acronym; } =head OUTPUT PINPAOR LP5E MRE =cut

    Of course, your spec leaves a little to be desired: how will you distinguish among Parts I, II and III of your first title?

    If your problem is in applying that answer to <a href="file:///foobar baz">Bazing with foo</a>, then you need to consider something on the order of HTML::Parser or another of the HTML::... modules.

    If you have some other stumbling block in your way, pray detail it, but without teaching Grandmother how to cook eggs with sed.