Operating System - HP-UX
1752790 Members
6515 Online
108789 Solutions
New Discussion юеВ

Re: String manipulation!!

 
SOLVED
Go to solution
Jonathan Caplette
Regular Advisor

String manipulation!!

Hi guys,

I wanna do a script that extract from a string "that is a filename" everything before the "." The thing is I don't know the lenght of the file name, but the extension is always the same... exemple: file1.txt I just want the "file1" not the extension .txt

I think I should use "cut" but I'm not familiar with cut...

Can somebody help me please!!
Regards
Jonathan
5 REPLIES 5
harry d brown jr
Honored Contributor
Solution

Re: String manipulation!!

cut -d"." -f1

live free or die
harry
Live Free or Die
Jonathan Caplette
Regular Advisor

Re: String manipulation!!

Thanks Harry!!

That's what I was trying to do!!!
Rodney Hills
Honored Contributor

Re: String manipulation!!

If it is a ksh script, you can do the following

x="the file name.txt"
y=${x%.*}
echo $y

will display-
the file name

-- Rod Hills
There be dragons...
Leif Halvarsson_2
Honored Contributor

Re: String manipulation!!

Hi
As I see you already got a answer whitch solve your problem but have a look at the command "basename" (and dirname), this command is "custom made" for this. For example:

"basename file1.txt .txt"

Will return "file1" .
harry d brown jr
Honored Contributor

Re: String manipulation!!

Leif,

I would have directed him to "basename", but I forgot the command, so I just showed him "cut".

live free or die
harry
Live Free or Die