LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-04-2012, 04:17 AM   #1
prravin1
Member
 
Registered: Feb 2012
Location: India
Posts: 43

Rep: Reputation: Disabled
Wink Create a folder from a file name


I have a files called STMam.bam.

Now i want to create a directory with the same name as the file but it should exclude the .bam extension.

The folder created should be named as STMam.
 
Old 05-04-2012, 04:27 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
erm... "mkdir STMam" will do that... if you're after help with scripting or programming, you need to provde more useful information here. the basename tool will probably help you a lot.
 
Old 05-04-2012, 04:50 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,887
Blog Entries: 1

Rep: Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873
Sg like this
Code:
FILENAME=stmam.bam; DIRNAME="${FILENAME%\.*}"; echo $DIRNAME
 
1 members found this post helpful.
Old 05-04-2012, 05:35 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
While I like the solution I am curious why the escape? A period is not special when globbing nor to the shell so the escape, as far as I can tell, serves no benefit.
 
Old 05-04-2012, 05:39 AM   #5
prravin1
Member
 
Registered: Feb 2012
Location: India
Posts: 43

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
While I like the solution I am curious why the escape? A period is not special when globbing nor to the shell so the escape, as far as I can tell, serves no benefit.
FNAME=file.ext
DIRNAME=$(echo ${FNAME/.*/})
echo $DIRNAME will show you directory name


mkdir "${FN%.*}"

DIR_NAME=$(echo ${FILENAME} | awk -F. '{ print $4 }')
mkdir ${DIR_NAME}
 
Old 05-04-2012, 07:16 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
I am not sure what you are trying to show here? Well apart from the fact that you are using your own solution and not the example by NevemTeve
 
Old 05-04-2012, 07:26 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,887
Blog Entries: 1

Rep: Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873
Sure, I checked the manual again, dot doesn't have special meaning in this context, so it is unnecessary to escape it. My fault.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Create folder name from the text file LinpusKelvin Programming 8 06-25-2010 11:43 AM
unable to create file & folder on fat32 file system while similiar other drives work sumeet inani Linux - Newbie 1 06-27-2009 11:46 AM
Can't create folder in file system using file browser aarav2306 Linux - Newbie 5 03-03-2009 01:36 AM
create a folder/file within a folder using perl indu.a Programming 2 03-07-2007 10:09 PM
how can i default the max folder file size when it create inside a folder antony_csf Linux - Software 1 06-17-2004 02:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration