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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using cut to count files

Status
Not open for further replies.

jestrada101

Technical User
Mar 28, 2003
332
How can I cut a variable to just show me the first part of the variable?

example... i could have the following..

a.g.d.a.g
b.b.dl.s.a.g
l.li.w.s.g.g
l.d.d.g

I only want the "g" returned? Can "cut" somehow work backwards to only remove teh last field....

Thanks
JE
 
ugly way of doing it, I'm not a sed or awk guru:

basename `echo "b.b.dl.s.a.g" | tr "." "/"`
 
Thanks..
but I would like the "g" stripped out... and be given everything prior that that..
from:
b.b.dl.s.a.g
to
b.b.dl.s.a


THANKS!
 
sed -e 's/\(.*\)\.g/\1/' myFile.txt

or if dealing POSIX shells:

a='b.b.dl.s.a.g'
b="${a%%.g}"

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
With base name :

basename 'a.b.c.d' .d

Anothers solutions like vgersh99 solution but more general :

sed -e 's/\.[^*]$//'

aaa.bbb.ccc -> aaa.bbb
aaa.bbb. -> aaa.bbb

With Posix shell :

${a%.*}


Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top