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

M

Mirik

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.
 
J

Josef Moellers

Mirik said:
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.
 
B

Brian McCauley

Mirik said:
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/;
 
B

Brian McCauley

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/;
 
M

Mirik

wow,
thanx much for great work...
Yes I want a " inserted at the start also.
Do You read my ideas? :)
Thanx oncemore.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top