![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
Have you tried using something like this:
find . | grep -i "^${name}*" No guarantees, but it's worth a shot, I suppose. |
|
#3
|
|||
|
|||
|
I would think that you could get just the file name by using cut. Like this:
cut -f1 -d. |
|
#4
|
||||
|
||||
|
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
|
|||
|
|||
|
i would honestly just opt for:
Code:
find / -name `ls $name|cut -f1 -d.` -print |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|