I want to sort the files first based on 2 byte alphabetic code (so that all CD's together all AA's together all DC's together). Next within that i want to sort on the basis of timestamp.
So file format is like ERyyEVENTlayymmddhhmmss.txt
where la=2 byte alphabetic code and rest is timestamp.
I tried using
ls -lrt *EVENT*|sort -r -k1.10,1.11 -k1.12,1.13 -k1.14,1.15 -k1.16,1.17 -k1.18,1.19 -k1.20,1.21 -k1.22,1.23
but my output is not proper the AA code files are not getting sorted properly.
Why is output different in case i do ls -lrt first and not take the list of files in a file and then sort the file..
Below output is different as mentioned above.
ls -lrt |sort -k1.10,23
total 80
-rwx------ 1 dsadm dstage 81 Oct 03 10:53 ER08EVENTAA080910224550.txt
-rwx------ 1 dsadm dstage 81 Oct 03 10:56 ER08EVENTAA080910232010.txt
-rwx------ 1 dsadm dstage 81 Oct 03 11:38 ER08EVENTAA080910130150.txt
-rwx------ 1 dsadm dstage 81 Oct 03 11:47 ER08EVENTAA080911015005.txt
-rwx------ 1 dsadm dstage 81 Oct 03 11:51 ER08EVENTAA080910232000.txt
-rwx------ 1 dsadm dstage 81 Oct 03 12:06 ER08EVENTAA080910130245.txt
-rwx------ 1 dsadm dstage 81 Oct 03 12:22 ER08EVENTCD080910130245.txt
-rwx------ 1 dsadm dstage 81 Oct 03 12:23 ER08EVENTCD080910222222.txt
-rwx------ 1 dsadm dstage 81 Oct 03 12:34 ER08EVENTCD080911232323.txt
-rwx------ 1 dsadm dstage 81 Oct 03 12:35 ER08EVENTDC080911232324.txt
Without recreating your filestructure, I copied the output of your ls -ltr to file9a
Which leave two choice. Cut out the 9th field from the data stream and then sort...
Or, sort on the 9th field
My previous example sorted on field 1, similar to the command you showed in your earlier example. (I assumed you cut to the 9th field so that you would sort on the field #1.)
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)
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)
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)
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)
Hi All,
I am new to Perl. I have a scenario to code. In a folder I have number of files and they will start with P01 or P02 or P03 and so on..I have to sort them on name first and then on time stamp.
Ex.
File name timestamp
P01_file1.txt 1PM
P02_file1.txt 1AM
P01_file2.txt 2PM... (12 Replies)
Hi All,
I am new to unix programming. I am trying for a requirement and the requirement goes like this.....
I have a test folder. Which tracks log files. After certain time, the log file is getting overwritten by another file (randomly as the time interval is not periodic). I need to preserve... (2 Replies)
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)