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 06-10-2007, 11:49 AM   #1
babag
Member
 
Registered: Aug 2003
Posts: 365

Rep: Reputation: 30
unwanted characters returned with bash find - how to remove?


this finds the first fiile in a directory:

find . -name "something-to-identify-with*" | sort -n | head -n 1

and this finds the last file:

find . -name "something-to-identify-with*" | sort -nr | head -n 1


one question: the directory i tested contains files in the naming
format:

Budgies_12345.bmp


the return from my cmd line is :

./Budgies_12345.bmp


what's with the ./? is there some simple syntaxing i
can use that will eliminate this from what is returned?

thanks,
BabaG
 
Old 06-10-2007, 01:31 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Hi,

You can call it a reference point.

You used find ., which says from the dir I'm in and all subdirs. If you would have used find /path/to/dir the output would have been /path/to/dir/Budgies_12345.bmp instead of ./Budgies_12345.bmp

Ok, that explains why it's there.

To answer your question:

One way of removing it is this (using sed):

find . -name "something-to-identify-with*" | sed 's%\./%%' | sort -nr | head -n 1

Hope this helps.
 
Old 06-10-2007, 01:35 PM   #3
babag
Member
 
Registered: Aug 2003
Posts: 365

Original Poster
Rep: Reputation: 30
thanks druuna. also got this from dawkcid:

basename $(find . -name "something-to-identify-with*" | sort -n | head -n 1)

thanks again,
BabaG
 
Old 06-10-2007, 01:39 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Hi,

basename will work, but if you have a deeper directory tree things could go wrong (depending on what you want to do). If the following is found: ./X/Y/somefile, basename will return somefile. It will also return somefile for the following: ./X/Y/Z/somefile.

But like I said, it all depends on what you want to do with the output.

Hope this clears things up.
 
Old 06-10-2007, 02:23 PM   #5
babag
Member
 
Registered: Aug 2003
Posts: 365

Original Poster
Rep: Reputation: 30
interesting. thanks!

BabaG
 
Old 06-10-2007, 09:36 PM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
if you don't mind full path names, you can also use full path
Code:
find $(pwd) -name "something-to-identify-with*" | sort -nr | head -n 1
 
  


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
How to remove unwanted data rvsridhar Linux - General 2 05-15-2006 03:07 PM
How to remove unwanted startup programs on mandrake 10.0 Scrag Linux - General 4 02-08-2006 11:38 AM
ld: cannot find -lc collect2: ld returned 1 exit status ArbuZz Linux From Scratch 3 09-27-2005 12:52 AM
remove unwanted openoffice.org-1.1.2 installed from apt-get provkitir Debian 3 10-12-2004 05:39 PM
Using Regular Expressions to find unwanted characters professorfrink Programming 1 10-07-2003 01:34 PM


All times are GMT -5. The time now is 04:32 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration