LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 02-15-2005, 05:30 PM   #1
XST1
LQ Newbie
 
Registered: Feb 2004
Posts: 11

Rep: Reputation: 0
Picking out the right file when ls | greping


I'm writing a script where I have to use ls | grep and search for a file in the current directory. I am assigning the name of this file to a variable so it needs to be precise. My only problem is that the file that I am grepping for has a brother which happens to have a different extension. I want to pick out the right file and send it to the variable.

Heres an example just to clarify:

I am in /home/m/temp

in the script I say:

a=`ls | grep myFile`

the value now stored in a is: myFile.exe myfFile.dll

I only want to store myFile.exe

How would I do this? Thanks.
 
Old 02-15-2005, 05:42 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Like this?
Code:
a=`ls  *exe| grep myFile`

Cheers,
Tink
 
Old 02-15-2005, 05:48 PM   #3
wapcaplet
LQ Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
Or why not just 'ls myFile'? Unless 'myFile' doesn't contain the full name of the file, in which case maybe 'ls myFile*'
 
Old 02-15-2005, 07:22 PM   #4
XST1
LQ Newbie
 
Registered: Feb 2004
Posts: 11

Original Poster
Rep: Reputation: 0
say I had "myfile.exe" stored in $a. How would I delete only the ".exe" part of it (without the quotes)?
 
Old 02-15-2005, 08:32 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally posted by XST1
say I had "myfile.exe" stored in $a. How would I delete only the ".exe" part of it (without the quotes)?
$b=$(basename ${a} .exe)


Cheers,
Tink
 
  


Reply



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
Need help on picking distro linuxputz Linux - Laptop and Netbook 5 09-02-2004 01:25 PM
picking a distro ? YBA^[x] Linux - Distributions 11 08-02-2004 12:31 PM
need help picking distro kurt9090 Linux - Distributions 10 05-03-2004 01:57 AM
picking off file extentions in php antken Linux - General 3 08-14-2002 03:49 PM
Needs help with picking the Opera D/L LX_NewBie Linux - Newbie 3 02-11-2002 06:28 PM

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

All times are GMT -5. The time now is 08:45 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