Bash - an odd problem using sed or awk or for

inode0 inode0 at gmail.com
Fri Nov 30 13:44:33 UTC 2012


On Fri, Nov 30, 2012 at 5:32 AM, John Horne <john.horne at plymouth.ac.uk> wrote:
> On Thu, 2012-11-29 at 18:56 -0600, inode0 wrote:
>
>>
>> Oh, for a simple variable this should work
>>
>> echo "${XX/*
>>
>> }"
>>
> Hello,
>
> Yes, that does seem to work :-)
>
> Although I have to admit I'm not sure why! I'll investigate further :-)

Basically it just drops the longest substring that matches the given
pattern (match anything followed by two newlines). This does
potentially miss some edge cases if you can have strings containing
only a single leading or possibly trailing blank line. But you can
remove leading and trailing blank lines if necessary or come up with
something more clever. See the "Parameter Expansion" section of the
bash man page for the details of this and other frequently useful ways
to expand/modify variables.

John


More information about the users mailing list