Re: Extract until unquote or EOL



Mats wrote:
>
> I've messed with this problem a while now. I want to parse a file for
> declarations (ex: NAME = "myname").
>
> I wan't to extract the phrase/text between the two quotes. BUT If the
> last quote isn't available (type/user error) then it should extract
> until end of line. If no quotes are there at all, it should extract the
> whole line (except NAME=). If there are several double quotes, it should
> extract between the first two (that i seem to have achived).
>
> My current testscript looks as below:
>
> ---
> #!/usr/bin/perl -w
>
> use strict;
>
> $_ = 'NAME = "between quotes" not this" nor this';
>
> print $1."\n" if m/\s*NAME\s*=\s*"*(.*?)"|$/s;
> ---
>
> This prints out as i want:
> between quotes
>
> But if i delete the last two doublequotes and just keep the first it
> prints nothing. If i delete the first doublequote also, i get an
> "uninitialized value" error.
>
> Anybody knows a smooth solution to this?

print "$1\n" if /\s*NAME\s*=\s*"?([^"]+)/;



John
.



Relevant Pages

  • Re: problem with spaces in quoted string arguments
    ... Janis Papanagnou wrote: ... are in double quotes. ... As can be seen in the output, the server called "photon hub" did not ... extract properly, since the space was detected in the argument to awk. ...
    (comp.unix.shell)
  • Re: Problem with Importing CSV with "=" inside a field value
    ... is a small Access database ... and have overcome a number of obstacles. ... it has an equal sign at the front and wrapped by quotes. ... Any way to skip parsing this field such that Access can extract the fields ...
    (microsoft.public.access.externaldata)
  • Re: Problem with Importing CSV with "=" inside a field value
    ... and have overcome a number of obstacles. ... it has an equal sign at the front and wrapped by quotes. ... This problematic field actually is of no use to me. ... Any way to skip parsing this field such that Access can extract the fields ...
    (microsoft.public.access.externaldata)
  • Re: Extract until unquote or EOL
    ... > I wan't to extract the phrase/text between the two quotes. ... NAME = no quotation marks so grab all of this ... NAME = "solitary quotation mark at the beginning of line, so grab all ...
    (comp.lang.perl.misc)
  • Problem with Importing CSV with "=" inside a field value
    ... and have overcome a number of obstacles. ... it has an equal sign at the front and wrapped by quotes. ... This problematic field actually is of no use to me. ... Any way to skip parsing this field such that Access can extract the fields ...
    (microsoft.public.access.externaldata)