Last word in line, BUT...!!!

Discussion in 'Perl Misc' started by Mirik, Sep 23, 2005.

  1. Mirik

    Mirik Guest

    Hi, is anybody who help me with script that I try to write?

    C:\TEMP\aaa\data
    C:\TEMP\bbb\data users
    C:\TEMP\ccc\data WUE00024\EDV:C
    C:\TEMP\ddd\data users WUE00010\EDV:X

    and I want to get this:
    all lines that do not contain second :, must have " at end,
    all lines that contain second :, must have " before last space


    like this
    "C:\TEMP\aaa\data"
    "C:\TEMP\bbb\data users"
    "C:\TEMP\ccc\data" GIE00024\EDA:C
    "C:\TEMP\ddd\data users" GOA00010\EDB:X

    Thankx much.
    Mirik, Sep 23, 2005
    #1
    1. Advertising

  2. Mirik wrote:
    > Hi, is anybody who help me with script that I try to write?
    >
    > C:\TEMP\aaa\data
    > C:\TEMP\bbb\data users
    > C:\TEMP\ccc\data WUE00024\EDV:C
    > C:\TEMP\ddd\data users WUE00010\EDV:X
    >
    > and I want to get this:
    > all lines that do not contain second :, must have " at end,
    > all lines that contain second :, must have " before last space
    >
    >
    > like this
    > "C:\TEMP\aaa\data"
    > "C:\TEMP\bbb\data users"
    > "C:\TEMP\ccc\data" GIE00024\EDA:C
    > "C:\TEMP\ddd\data users" GOA00010\EDB:X


    Sigh! (looking slightly bored, drumming with my fingers on my desk) What
    have you tried so far, where have you failed?
    Please read the posting guidelines. This is not a "please send
    money^Wcode" place.

    So: post some attempts and we'll try to help.
    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett
    Josef Moellers, Sep 23, 2005
    #2
    1. Advertising

  3. Mirik wrote:

    > Hi, is anybody who help me with script that I try to write?
    >
    > C:\TEMP\aaa\data
    > C:\TEMP\bbb\data users
    > C:\TEMP\ccc\data WUE00024\EDV:C
    > C:\TEMP\ddd\data users WUE00010\EDV:X
    >
    > and I want to get this:
    > all lines that do not contain second :, must have " at end,
    > all lines that contain second :, must have " before last space


    I shall assume you meant to include the word "inserted" (i.e. there's no
    need to check if there a quote already.

    I shall also assume that "second colon" can be changed to "colon after
    the last space" as this makes the problem a lot simpler.

    > like this
    > "C:\TEMP\aaa\data"
    > "C:\TEMP\bbb\data users"
    > "C:\TEMP\ccc\data" GIE00024\EDA:C
    > "C:\TEMP\ddd\data users" GOA00010\EDB:X


    You forgot to mention you also want a " inserted at the start.

    s/^(.*?)(( [^ ]*:[^ ])?)$/"$1"$2/;
    Brian McCauley, Sep 23, 2005
    #3
  4. Brian McCauley wrote:

    You forgot to mention you also want a " inserted at the start.
    >
    > s/^(.*?)(( [^ ]*:[^ ])?)$/"$1"$2/;
    >


    Oops. That assumes the colon is the penutimate character. Although this
    was true of the OP's test data it wasn't part of the spec....

    s/^(.*?)(( [^ ]*:[^ ]*)?)$/"$1"$2/;
    Brian McCauley, Sep 23, 2005
    #4
  5. Mirik

    Mirik Guest

    wow,
    thanx much for great work...
    Yes I want a " inserted at the start also.
    Do You read my ideas? :)
    Thanx oncemore.
    Mirik, Sep 23, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Giagnocavo [MVP]

    Re: read a word doc line by line

    Michael Giagnocavo [MVP], Sep 30, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    366
    Michael Giagnocavo [MVP]
    Sep 30, 2003
  2. Frost
    Replies:
    8
    Views:
    512
    Vladimir S. Oka
    Feb 10, 2006
  3. Joe Van Dyk

    getting the last word in each line

    Joe Van Dyk, Sep 12, 2006, in forum: Ruby
    Replies:
    6
    Views:
    85
    Logan Capaldo
    Sep 13, 2006
  4. Replies:
    10
    Views:
    263
    Robert Klemme
    Oct 11, 2008
  5. Replies:
    8
    Views:
    203
    Dennis Lee Bieber
    Dec 19, 2012
Loading...

Share This Page