$ ls -lrt
total 50
lms_prap_rf_20100422_99.xml
lms_prap_rf_20100422_9.xml
lms_prap_rf_20100422_100.xml
lms_prap_rf_20100422_10.xml
lms_prap_rf_20100426_1.xml
I need to get the sorting of the above file based on numbers. I need first file in ascending order.
I am using the code as
ls -l lms_prap_rf* | sort -t _ -nk4 -k5 | head -1
which gives me correct one as
lms_prap_rf_20100422_9.xml
but when I am doing it with the directory I am not getting what I want because my directories consist of underscores.
ls -1 /c09/oracle/XX_TT/12.0.0/TMP_IN/lms_prap_rf* | sort -t _ -nk4 -k5 | head -1
how to avoid the directory path while doing sort. Please not I need to run this script in 2 or 3 environment where the directory path may different and may have more underscores
I think the problem is that your path name contains "_" character. when you use ls path/file_prefix* or ls -l path/file_prefix*. Try to cd into that directory and then do "ls file_prefix*" instead.
Thanks Yes I do understand that the issue is with the underscore "_" in my path. But I am using this in my shell script and I don't want to use cd command in there.
Is there any way I can ls on the directory and remove the directory path from my result and do sort on it.?
Thanks and Regards,
Sreejit
---------- Post updated at 10:37 AM ---------- Previous update was at 09:59 AM ----------
Hi All-
I am trying the below, can anybody please let me know if I am doing anything wrong.
ls ${path_to_files}/lms_prap_rf* | nawk -F/ '{print $NF}' | sort -t _ -nk4 -k5 | head -1