Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

quick question about sed pls... 2

Status
Not open for further replies.

h3nd

Programmer
Jul 1, 2006
147
AU
Hi guys,

I just wanna remove the last instance (*) of value :

the original value is :
*generic.sh*5*

I have tried :
echo "*generic.sh*5*" | sed -e 's/\*//'

But it didnt work, any idea ??

Thanks,
 
you wanted this ?
echo "*generic.sh*5*" | sed -e 's/\*[!]$[/!]//'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thx PHV,

but what about using awk, because what I'm doing like this :
Code:
echo "[Nov 09 10:10:31] DONE[1] := 1 := *generic.sh*5*" | awk -F ":=" '{print $3}' | sed 's/\*//1;s/\*$//'

I want to remove the first instance and last instance,
so if I can use awk, that would be neater script..

Thx man
 
Like this ?
awk -F ":=" '{x=$3;sub(/\*/,"",x);sub(/\*$/,"",x);print x}'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV,

one more question:

what about I wanna remove second and the last :
I've tried this doesnt work
Code:
awk -F ":=" '{x=$3;gensub(/*/,"",2,x);sub(/*$/,"",x);print x}'

Thanks man
 
awk man page said:
Unlike sub() and gsub(), the modified string is returned as the result of the function, and the original target string is not changed.

So this should work as expected:

Code:
awk -F ":=" '{x=gensub(/*/,"",2,$3);sub(/*$/,"",x);print x}'

Annihilannic.
 
Thanks Anni,

You're so brilliant !!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top