The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
substring ?? varungupta Shell Programming and Scripting 7 10-01-2007 06:18 AM
substring panknil Shell Programming and Scripting 4 10-01-2007 05:12 AM
How do I Substring ?? Rigger Shell Programming and Scripting 6 04-25-2007 11:26 PM
substring alla.kishore UNIX for Dummies Questions & Answers 8 01-08-2007 11:57 PM
substring using AWK mahabunta UNIX for Dummies Questions & Answers 3 09-19-2006 01:47 PM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 09-19-2001
Registered User
 

Join Date: Jan 2001
Location: The Netherlands
Posts: 4
Question substring

Hi,

I've got a UNIX-script in which a variable 'name' is used. This variable is filled with a filename (e.g. file.tst). Now I want to search for files which start with the same name, but without the extension, e.g. file_test. Is there a way of doing this, using something like substring or something equal?

Thanks in advance,

Anika
Forum Sponsor
  #2  
Old 09-19-2001
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Have you tried using something like this:
find . | grep -i "^${name}*"
No guarantees, but it's worth a shot, I suppose.
  #3  
Old 09-19-2001
Registered User
 

Join Date: Sep 2001
Location: Omaha, NE
Posts: 6
I would think that you could get just the file name by using cut. Like this:

cut -f1 -d.
  #4  
Old 09-19-2001
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,613
If you're using ksh it's just:
find / -name ${name%.*}\* -print

If you're using a lower voltage shell, there is always basename, but basename can remove a specific suffix:
find / -name `basename $name .txt` -print

To remove any suffix without using ksh, you will need to use sed, but the syntax is nasty:
find / -name `echo $name | sed 's/\([^.]*\).*/\1/'` -print

And yes, these days you don't need the -print anymore, but I'm a traditional kind of guy.
  #5  
Old 09-19-2001
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
i would honestly just opt for:
Code:
find / -name `ls $name|cut -f1 -d.` -print
reasons being. $name is already defined earlier in the script so no need to make more of a mess. That and im not a huge fan of useing shell specific variables. I like to keep the code as protable as possable.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0