Finding the lowest sequenced file in a directory?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Finding the lowest sequenced file in a directory?
# 1  
Old 06-06-2008
Finding the lowest sequenced file in a directory?

Hello,

I have three files in a directory:


1_700_123456.lst
1_701_123456.lst
1_702_123456.lst





I am trying to use a command via ksh that will list the file that has the lowest number in the second node and put that to a file.

In the example above, it would put 1_700_123456.lst in a file.



Any ideas on how to do this easily?



Thanks!
# 2  
Old 06-06-2008
Code:
ls -l | sort -t_ -nk2,2 | head -1

# 3  
Old 06-06-2008
Try something like this:

Code:
awk -F"_" '!m || $2<m{m=$2;s=$0}END{print s}' file

Regards
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding the file name in a directory with a pattern

I need to find the latest file -filename_YYYYMMDD in the directory DIR. the below is not working as the position is shifting each time because of the spaces between(occuring mostly at file size field as it differs every time.) please suggest if there is other way. report =‘ls -ltr... (2 Replies)
Discussion started by: archana25
2 Replies

2. UNIX for Dummies Questions & Answers

Finding new file, but excluding directory..

hi, I need to find files that have been created less than 3 days ago. However, I need to only search specific directories. I've searched about the net and found some useful commands such as : find . -type d -name 'dir_to_exclude' -prune -o -print -mtime -3 however I cannot get it... (2 Replies)
Discussion started by: horhif
2 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Finding the latest file in a directory

Hi All, I am using the below command to find the latest file in a dir: ls -tr $v_sftphomedir/$v_sourcefile |tail -1 or ls -t1 $v_sftphomedir/$v_sourcefile |head -1 and the outpur returned is below: /home/cobr_sftp/var/controllingload/Backup/Dbrwds_Div_1796050246.txt I need only the... (5 Replies)
Discussion started by: abhi_123
5 Replies

4. Shell Programming and Scripting

finding lowest numbers

i want to basically get the lowest numbers from a list ... for example my input file is .... 1 2 3 6 7 8 9 10 11 13 Now i want to create a script or a one liner which i can use like this ... for example ..../getlowest 3 --> this gives me the next 3 lowest numbers which... (6 Replies)
Discussion started by: greycells
6 Replies

5. UNIX for Dummies Questions & Answers

Finding file in a directory structure + move

Hi All, im a new guy if it comes to Unix. I am trying to auto categorize Nzbget downloads the most basic way. I already manage to find files within the directory i'm at and move them with if check to a certain dir. Unfortunately this command is restricted to the directory i'm at and does not... (2 Replies)
Discussion started by: RoxXxoR
2 Replies

6. UNIX and Linux Applications

Finding the oldest file in a directory without ls

I am trying to determine the oldest and most recent files in a huge directory. I am using an ls -tr statement outside my find statement. The directory is too big and I am getting an "arg list too long" error. Is there something I can put in my find statement that doesn't create a list to... (2 Replies)
Discussion started by: hiyofjord
2 Replies

7. Shell Programming and Scripting

Korn Shell - Finding lowest number of a file.

I'm writing a KSH script that will get a file on the command line (such as input.txt), and in this file there is on number per line. The program needs to take the file, read each and determine the lowest number in the file. I currently have a while loop setup that will correctly out put every... (8 Replies)
Discussion started by: denyal
8 Replies

8. Shell Programming and Scripting

Finding the oldest file in a particular directory

Hi all, I am a newbie to scripting and I need your help regarding finding the oldest file in a particular directory. My intention is to remove that oldest file. Are there any options available with the "find" command to do this.. Thanks in advance for your help Pavan (4 Replies)
Discussion started by: pavan_movva
4 Replies

9. Programming

Finding largest file in current directory?

I was hoping to get some assistance with this C program I am working on. The goal is to find the largest file in the current directory and then display this filename along with the filesize. What I have so far will display all the files in the current directory. But, how do I deal with "grabbing"... (1 Reply)
Discussion started by: AusTex
1 Replies

10. UNIX for Dummies Questions & Answers

finding file in a directory

hi can i know how to locate a file in a directory by using the "find" command? i want to know the exact path the files reside in in the result. thanks :confused: (4 Replies)
Discussion started by: legato
4 Replies
Login or Register to Ask a Question