LinuxQuestions.org
Visit the LQ Articles and Editorials section
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-16-2003, 11:36 AM   #1
brian0918
Member
 
Registered: Apr 2003
Posts: 87

Rep: Reputation: 15
bash scripting - largest # file extension


I have files named bleh.1, bleh.2, bleh.3, bleh.4... bleh.10, etc. that are being created, and want to track their progress. Is there a way to find the largest extension (1, 2, 3, ... 10, etc) of the set of files named "bleh", then be able to use that extension to look at that file (if 10 is the largest then view bleh.10)?

note- the newest files will have the largest extension, so maybe there's a way to do it with some sort of search for the newest file, then grab its extension somehow, and use that extension with the set of files named "bleh" (ie: The newest file found is xyz.10, so look at bleh.10)

Thanks.
 
Old 06-16-2003, 11:47 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
To view the newest file which name starts with "bleh":
Code:
less `ls -tr bleh* | tail -1`
To view the file with the highest number as its extension:
Code:
less bleh.`ls bleh* | sed 's/bleh.*\.\([0-9]*\)/\1/' | sort -n | tail -1`
Of course, you can use "more" or "cat" or "view" instead to view the file...
 
Old 06-16-2003, 11:58 AM   #3
brian0918
Member
 
Registered: Apr 2003
Posts: 87

Original Poster
Rep: Reputation: 15
Thanks for the reply.

Your suggestions work, but my problem now is that I'm trying to do this in a script, similar to this:

y=$(ls -tr bleh* | tail -1)

Now what I want to do is grep info from this file, using something like:

echo " `grep "blah" $y` "

I'm not sure, but I think I tried using this syntax before, and it didn't work. Is this the correct way to do it?

Thanks.
 
Old 06-16-2003, 12:06 PM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Quote:
Originally posted by brian0918
Now what I want to do is grep info from this file, using something like:

echo " `grep "blah" $y` "

[..snip..]Is this the correct way to do it?
Just:

grep "blah" $y

will do...
 
  


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
BASH Shell Scripting -- foreach file in folder??? AC97Conquerer Programming 11 07-06-2011 12:25 AM
Bash Scripting Empty file john8675309 Linux - Software 2 08-08-2007 04:05 PM
bash scripting - how to make config file? Neorio Programming 3 10-22-2004 06:39 AM
bash scripting read from file cadj Programming 2 02-29-2004 10:42 PM
bash scripting - how long ago file was modified brian0918 Programming 3 06-19-2003 04:10 PM


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