05-10-2012
sort
Quote:
Originally Posted by
unankix
Hi Ranga,
Thanks for the reply.
I am using the script to sort the files in a folder in order to timestamp:
opendir(DIR,$directory)|| die "Error in opening dir $directory\n";
my @sorted_files =
map $_->[1],
reverse sort { $a->[0] <=> $b->[0] }
map -f "$directory/$_" ? [ ( stat _ )[9], $_ ] : (),
readdir(DIR);
closedir(DIR)
@sorted_files=sort(@sorted_files);
Can you please let me know if there is any way I can modifythis script to first sort the files on name and then on Timestamp.
If you will explain your answer,that will be great help.
Thanks.
Dont take this req as a big deal. In perl, sort function sort the array as you required.
Cheers,
Ranga
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi,
I have files like
ER08EVENTDC080911232324.txt
ER08EVENTCD080911232323.txt
ER08EVENTCD080910222222.txt
ER08EVENTCD080910130245.txt
ER08EVENTAA080910130245.txt
ER08EVENTAA080910232000.txt
ER08EVENTAA080911015005.txt
ER08EVENTAA080910130150.txt
ER08EVENTAA080910232010.txt... (5 Replies)
Discussion started by: harshada
5 Replies
2. Shell Programming and Scripting
Dear all,
Please advice how do I sort a file based on timestamp information. I want to sort the second column in asc/desc order which has timestamp information in format YYYY-MM-DD HH:MM:SS
Example
File - Input.txt contains
cat ss.txt
100|2009-03-30 11:38:43
141|2009-06-01 12:12:01... (1 Reply)
Discussion started by: sureshg_sampat
1 Replies
3. UNIX for Dummies Questions & Answers
Team,
Pls help writing a shell script which will sort all the files in a directory with the timestamp they were created. (like ls -lrt) (6 Replies)
Discussion started by: asappidi
6 Replies
4. Shell Programming and Scripting
Hi
I have a requirement like below
I need to sort the files based on the timestamp in the file name and run them in sorted order and then archive all the files which are one day old to temp directory
My files looks like this
PGABOLTXML1D_201108121235.xml... (1 Reply)
Discussion started by: saidutta123
1 Replies
5. Homework & Coursework Questions
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
I must write a shell script that calls two external Perl functions--one of which sorts the data in a file, and... (6 Replies)
Discussion started by: kowit010
6 Replies
6. Shell Programming and Scripting
I need to be able to identify files with file timestamps greater than a given timestamp.
I am using the following solution, although it appears to compare files at the "seconds" granularity and I need it at the milliseconds. When I tested my solution, it missed files that had timestamps... (3 Replies)
Discussion started by: nkm0brm
3 Replies
7. Shell Programming and Scripting
Hi,
Trying to sort grep result based on timestamp of the filename.
I have the following result and want to sort them on timestampgrep -i 'ERROR' *log*2013*
s_m_xxx_xxx_xxx_xxx_xxxx.log.20130906092431:TRANSF_1_1_1> DBG_21216 Finished transformations for Source Qualifier . Total errors ... (5 Replies)
Discussion started by: bobbygsk
5 Replies
8. Shell Programming and Scripting
originally the shellscript
#ln_file_name=`echo $ld_interface_date"_"${8}".csv"`
#ln_file_name=`echo 201202011527_HL_HLTM1_B04A.csv`
ln_file_name="*"`echo ${7}".csv"`
get_file_list_1=$log_path"tm1_file_list.gfl1"
cd ${source_path}
echo "Try to find any file exist in the... (10 Replies)
Discussion started by: feilhk
10 Replies
9. Shell Programming and Scripting
Hello,
I have a sample file with the below contents :
Backup Oracle8_P112_PEGA_Archivedel Completed full 10/11/2015 03:50:06PM
Backup Oracle8_G567_PEGA_Archivedel Completed full 10/11/2015 01:15:56PM
Backup Oracle8_P112_PEGA_Archivedel Completed full ... (8 Replies)
Discussion started by: rahul2662
8 Replies
10. Shell Programming and Scripting
Used below command to get list of files sorted by timestamp
find -L . -type f -name '*dat*' | xargs ls -ltrg
I want to get only the filenames so I tried adding basename but it doenst work , can some one advise on how to get only file name (1 Reply)
Discussion started by: lalitpct
1 Replies
LEARN ABOUT MOJAVE
fdopendir
DIRECTORY(3) BSD Library Functions Manual DIRECTORY(3)
NAME
opendir, fdopendir, readdir, readdir_r, telldir, seekdir, rewinddir, closedir, dirfd -- directory operations
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <dirent.h>
DIR *
opendir(const char *filename);
DIR *
fdopendir(int fd);
struct dirent *
readdir(DIR *dirp);
int
readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
long
telldir(DIR *dirp);
void
seekdir(DIR *dirp, long loc);
void
rewinddir(DIR *dirp);
int
closedir(DIR *dirp);
int
dirfd(DIR *dirp);
DESCRIPTION
The opendir() function opens the directory named by filename, associates a directory stream with it and returns a pointer to be used to iden-
tify the directory stream in subsequent operations. The pointer NULL is returned if filename cannot be accessed, or if it cannot malloc(3)
enough memory to hold the whole thing, and sets the global variable errno to indicate the error.
The fdopendir() function is equivalent to the opendir() function except that the directory is specified by a file descriptor fd rather than
by a name.
Upon successful return from fdopendir(), the file descriptor is under the control of the system, and if any attempt is made to close the file
descriptor, or to modify the state of the associated description other than by means of closedir(), readdir(), readdir_r(), or rewinddir(),
the behavior is undefined. Upon calling closedir() the file descriptor is closed. The FD_CLOEXEC flag is set on the file descriptor by a
successful call to fdopendir().
The readdir() function returns a pointer to the next directory entry. It returns NULL upon reaching the end of the directory or on error.
In the event of an error, errno may be set to any of the values documented for the getdirentries(2) system call. Note that the order of the
directory entries vended by readdir() is not specified. Some filesystems may return entries in lexicographic sort order and others may not.
The readdir_r() function provides the same functionality as readdir(), but the caller must provide a directory entry buffer to store the
results in. If the read succeeds, result is pointed at the entry; upon reaching the end of the directory result is set to NULL. The
readdir_r() function returns 0 on success or an error number to indicate failure.
The telldir() function returns the current location associated with the named directory stream. Values returned by telldir() are good only
for the lifetime of the DIR pointer, dirp, from which they are derived. If the directory is closed and then reopened, prior values returned
by telldir() will no longer be valid.
The seekdir() function sets the position of the next readdir() operation on the directory stream. The new position reverts to the one asso-
ciated with the directory stream when the telldir() operation was performed.
The rewinddir() function resets the position of the named directory stream to the beginning of the directory.
The closedir() function closes the named directory stream and frees the structure associated with the dirp pointer, returning 0 on success.
On failure, -1 is returned and the global variable errno is set to indicate the error.
The dirfd() function returns the integer file descriptor associated with the named directory stream, see open(2). On failure, -1 is returned
and the global variable errno is set to indicate the error.
Sample code which searches a directory for entry ``name'' is:
dirp = opendir(".");
if (dirp == NULL)
return (ERROR);
len = strlen(name);
while ((dp = readdir(dirp)) != NULL) {
if (dp->d_namlen == len && strcmp(dp->d_name, name) == 0) {
(void)closedir(dirp);
return (FOUND);
}
}
(void)closedir(dirp);
return (NOT_FOUND);
SEE ALSO
close(2), lseek(2), open(2), read(2), dir(5)
HISTORY
The opendir(), readdir(), telldir(), seekdir(), rewinddir(), closedir(), and dirfd() functions appeared in 4.2BSD. The fdopendir() function
appeared in FreeBSD 8.0.
BSD
April 16, 2008 BSD