How to remove a substring 
Author Message
 How to remove a substring

Hi All,
I have the following variable:
TEST=c:/dummy/simple/easy.exe
I would like to have a new variable with the following content:
NEW_TEST=c:/dummy/simple
How you can see I want to remove the easy.exe string ( it could be also
"easy"
without ".exe" ).
Thanks and ciao,
                            Paul


Mon, 12 Aug 2002 03:00:00 GMT  
 How to remove a substring

Quote:

> I have the following variable:
> TEST=c:/dummy/simple/easy.exe
> I would like to have a new variable with the following content:
> NEW_TEST=c:/dummy/simple
> How you can see I want to remove the easy.exe string (it could be also
> "easy" without ".exe").

Use sub(). The regular expression pattern should match a slash,
followed by zero or more occurrences of the class of characters
other than a slash, all at the end of the string.

But that's the awk answer to your ostensibly awk question. The
better way is to use dirname if you have it.

--
Jim Monty

Tempe, Arizona USA



Mon, 12 Aug 2002 03:00:00 GMT  
 How to remove a substring


Quote:
>Hi All,
>I have the following variable:
>TEST=c:/dummy/simple/easy.exe
>I would like to have a new variable with the following content:
>NEW_TEST=c:/dummy/simple
>How you can see I want to remove the easy.exe string ( it could be also
>"easy"
>without ".exe" ).

This sounds like you want a shell answer rather than an awk answer.

In unix you could do:

#!/bin/sh
TEST=c:/dummy/simple/easy.exe
NEW_TEST=`dirname $TEST`
echo $NEW_TEST

which outputs:

c:/dummy/simple

If you really want an awk solution, here's one:

#!/bin/sh
TEST=c:/dummy/simple/easy.exe
NEW_TEST=`echo $TEST|awk '{t=$0;sub(/\/[^\/]*$/,"",t);print t}'`
echo $NEW_TEST

which outputs:

c:/dummy/simple

I could have not used t, but this shows how to do it from an
awk variable.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Mon, 12 Aug 2002 03:00:00 GMT  
 How to remove a substring
Use:
    cut -c1-15 to get rid of ".exe" and then concatenate two strings.

Dj

"My palm is hairy and my eyes are starting to give.  Help ?..."

Quote:

> Hi All,
> I have the following variable:
> TEST=c:/dummy/simple/easy.exe
> I would like to have a new variable with the following content:
> NEW_TEST=c:/dummy/simple
> How you can see I want to remove the easy.exe string ( it could be also
> "easy"
> without ".exe" ).
> Thanks and ciao,
>                             Paul



Mon, 12 Aug 2002 03:00:00 GMT  
 How to remove a substring


Quote:
>Hi All,
>I have the following variable:
>TEST=c:/dummy/simple/easy.exe
>I would like to have a new variable with the following content:
>NEW_TEST=c:/dummy/simple
>How you can see I want to remove the easy.exe string ( it could be also
>"easy"
>without ".exe" ).

Paul,

Your email address bounces mail sent to it.

You'd emailed a followup, and when I answered it, it bounced.

If you want help, use an address that doesn't bounce.

BTW, that REALLY pissed me off.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Fri, 16 Aug 2002 03:00:00 GMT  
 How to remove a substring

Quote:

>Hi All,
>I have the following variable:
>TEST=c:/dummy/simple/easy.exe
>I would like to have a new variable with the following content:
>NEW_TEST=c:/dummy/simple
>How you can see I want to remove the easy.exe string ( it could be also
>"easy"
>without ".exe" ).
>Thanks and ciao,
>                            Paul

If there's no dot in the pathname:
    NEW_TEST=`echo $TEST | cut -d. -f1`

If there is probably a dot in the pathname:
    NEW_TEST=`echo $TEST | dirname`/` echo $TEST | cut -d. -f1`

I don't have a solution if there's a dot in the filename.

Greetings from Switzerland
Happl



Sat, 17 Aug 2002 03:00:00 GMT  
 How to remove a substring

Quote:

>I have the following variable:
>TEST=c:/dummy/simple/easy.exe
>I would like to have a new variable with the following content:
>NEW_TEST=c:/dummy/simple

If you must use an awk, this illustrates another method:

NEW=`echo $TEST |awk -F/ '{OFS="/";NF=NF-1;print}'`
--
John Savage            (for email, replace "ks" with "k" and delete "n")



Sat, 24 Aug 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. replace substring by spaces - taking same space as substring

2. hacks for remove and remove!

3. Determining if a field is a substring of another field

4. Output a substring based on a regexp?

5. Ultra Newbie - Search for two patterns and extract substring

6. Newbie Question - Replcaing within a substring

7. substring 94 characters

8. substring variable

9. Print a substring

10. substring replacement question

11. Search substring in MEMO field

12. substring sort

 

 
Powered by phpBB® Forum Software