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

strip file extension from a string 1

Status
Not open for further replies.

PJD1

IS-IT--Management
Dec 4, 2006
2
0
0
GB
Hi Guys
I have a string $INV which is in the format 123456.csv
I need to strip the .csv off so I can use the first part of the string to compare agains a database col.
I'm quite new to the unix scripting language and would assume you could use sed but can't quite work out the syntax.
Is sed the best thing to use of is there some other command I could use.

Many thanks
 
Hi

Code:
[blue]master #[/blue] echo "${INV%.*}"
123456

[blue]master #[/blue] basename "$INV" .csv
123456

[blue]master #[/blue] echo "$INV" | sed 's/\..*//'
123456


Feherke.
 
Hi PJD1,

You could try new_var=${INV%.csv}

I'm sure some of the bigger brains on this forum will provide you with the sed syntax.

Hope this helps.

Alan
 
thanks guys for your quick response - and I got 3 answers for the price of 1 :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top