1833048 Members
2419 Online
110049 Solutions
New Discussion

shell tricks

 
SOLVED
Go to solution
Philip J. Priest_1
Frequent Advisor

shell tricks

I have a file like this:

treasury_server.SCANTU.1.205.219.16.253.06-14-05.09:42:57.log

i need to strip off eveything after SCANTU.

how can i do this?

thanks!
Phil
9 REPLIES 9
Pedro Cirne
Esteemed Contributor

Re: shell tricks

Hi,

Use "ls treasury*|cut -c1-22"

Enjoy :)
Juan M Leon
Trusted Contributor

Re: shell tricks

Phil; try this

filename=treasury_server.SCANTU.1.205.219.16.253.06-14-05.09:42:57.log
newfilename=`echo $filename | cut -d"." -f1`

the newfilename shouldbe "treasury_server"

Hope it helps.
RAC_1
Honored Contributor
Solution

Re: shell tricks

awk -F "." '{print $1,$2}' "your_file"

Anil
There is no substitute to HARDWORK
Mel Burslan
Honored Contributor

Re: shell tricks

if you want the output to include SCANTU as well

ls | cut -d. -f1-2



if not

ls | cut -d. -f1

if you have multiple file like treasury* you can put thw wildcard pattern instead of filename here as well.

hope it helps
________________________________
UNIX because I majored in cryptology...
Rodney Hills
Honored Contributor

Re: shell tricks

How about-

x="treasury_server.SCANTU.1.205.219.16.253.06-14-05.09:42:57.log"
echo ${x%SCANTU*}

This will strip off the SCANTU also, but you could add that back on...

HTH

-- Rod Hills
There be dragons...
Sandman!
Honored Contributor

Re: shell tricks

Slight variation on RAC's solution...

echo treasury_server.SCANTU.1.205.219.16.253.06-14-05.09:42:57.log | awk -F".1" '{print $1}'

enjoy!
Muthukumar_5
Honored Contributor

Re: shell tricks

You can do as,

echo treasury_server.SCANTU.1.205.219.16.253.06-14-05.09:42:57.log | sed 's/SCANTU.*/SCANTU/'

echo treasury_server.SCANTU.1.205.219.16.253.06-14-05.09:42:57.log | cut -d '.' -f1,2

hth.
Easy to suggest when don't know about the problem!
Dietmar Konermann
Honored Contributor

Re: shell tricks

Rodney's approach is by far fastest one, since it does not use external commands. All others are breaking a fly on a wheel, IMHO.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Philip J. Priest_1
Frequent Advisor

Re: shell tricks

All of these are good. I used awk.
Thanks for everyone who responded!

Phil