Results 1 to 5 of 5
Say I have this string stored in a variable
var='f:\dd\vctools\crt_bld\SELF_X86\crt\src\INTEL\ mt_lib\chandler4.obj'
I want to only get 'chandler4.obj' this string and store it into another variable. To be more specific, the ...
- 10-05-2008 #1Just Joined!
- Join Date
- Oct 2008
- Posts
- 2
how to extract a string from a variable?
Say I have this string stored in a variable
var='f:\dd\vctools\crt_bld\SELF_X86\crt\src\INTEL\ mt_lib\chandler4.obj'
I want to only get 'chandler4.obj' this string and store it into another variable. To be more specific, the string that comes after the \ character. I'm reading about a thousand of those from a file so it'd be nice to have a way to do the task in an automated fashion. How would one go about making a bash script that does that?
Thanks!
- 10-05-2008 #2
Hello,
look into the "basename" command.Debian GNU/Linux -- You know you want it.
- 10-05-2008 #3Just Joined!
- Join Date
- Oct 2008
- Posts
- 2
Thanks! I'll look into it.
- 10-05-2008 #4Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
If you find that the shell and basename do not seem to do the right thing with backslash in your Windows pathname as opposed to (forward)-slash, then re-post with your command / script ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 10-05-2008 #5Linux User
- Join Date
- Jun 2007
- Posts
- 318
basename won't work with backslashes. This will work:
Code:#!/bin/bash -vx var='f:\dd\vctools\crt_bld\SELF_X86\crt\src\INTEL\ mt_lib\chandler4.obj' echo "${var##*\\}"


Reply With Quote