Sponsored Content
Top Forums Shell Programming and Scripting Sorting issue with directory and file name Post 302421497 by sreejitnair123 on Friday 14th of May 2010 12:17:00 PM
Old 05-14-2010
Sorting issue with directory and file name

Hi All,

My folder contains the files as:

Code:
$ 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
Code:
ls -l lms_prap_rf* | sort -t _ -nk4 -k5 | head -1

which gives me correct one as
Code:
 
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.

Code:
ls -1 /c09/oracle/XX_TT/12.0.0/TMP_IN/lms_prap_rf* | sort -t _ -nk4 -k5 | head -1

I am getting the wrong answer as
Code:
/c09/oracle/XX_TT/12.0.0/TMP_IN/lms_prap_rf_20100422_10.xml

My main code is looking for
Code:
in_file=`ls -1 $file_path/$file_name* | sort -t _ -nk4 -k5 | head -1`

where
Code:
file_path=]/c09/oracle/XX_TT/12.0.0/TMP_IN

and
Code:
file_name=lms_prap_rf

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

Please advice.

Regards,
Sreejit
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting files in a directory

Hi guys, Probably an easy one, but how do you sort a directory so that the files come first, then subdirectories? ie ./dir1 contains file 1 subdir 1 file 2 i need it to become file 1 file 2 subdir 1 as i'm using it in a script to pass each one through a for loop, and would... (2 Replies)
Discussion started by: olimiles
2 Replies

2. UNIX for Dummies Questions & Answers

Sorting files in a directory

Hi guys, Probably an easy one, but how do you sort a directory so that the files come first, then subdirectories? ie ./dir1 has file 1 subdir 1 file 2 i need it to become file 1 file 2 subdir 1 as i'm using it in a script to pass each one through a for loop, and would like all... (3 Replies)
Discussion started by: olimiles
3 Replies

3. UNIX for Dummies Questions & Answers

Sorting Directory Listing

If I do an ls -l on a directory I get this: -rw-r--r-- 1 root other 5248094 Jun 24 03:56 monitor.log.7 -rw-r--r-- 1 root other 5248303 Jul 11 11:19 ct.log.1 -rw-r--r-- 1 root other 5248907 Jun 29 06:01 ct_monitor.log.5 -rw-r--r-- 1 root other 5249042 Jun 19... (1 Reply)
Discussion started by: Sepia
1 Replies

4. Shell Programming and Scripting

Sorting Issue

Hi Guys, I am very new to Unix.Can anyone tell me how to sort a file based on fields. For example, I am having a file whose contents are mentioned below: 2233|charles harris |g.m. |sales |12/12/52| 90000 9876|bill johnson |director... (3 Replies)
Discussion started by: mraghunandanan
3 Replies

5. UNIX for Dummies Questions & Answers

Issue on sorting

Hi, I have a file which has data as path/1.xml path/2.xml,...(each in separate lines) I want to sort this file in order. It is not working when I give "sort filename" The number of "/" in path can vary. Thanks, Floyd (1 Reply)
Discussion started by: asmfloyd
1 Replies

6. Shell Programming and Scripting

Sorting by Full directory path

I have a text file with full list of files with their full path. I wanted to sort it by directory then files then subdirectory by alphabetically. When I used the sort command it doesn't give like what I want. Could somebody help me on this. Here is the ex: This is what I'm getting... (2 Replies)
Discussion started by: javidraaj
2 Replies

7. Shell Programming and Scripting

An Issue with the script which used to remove a file from the current directory.

Hello forum members, I am writing a script to two tasks. 1: displaying the list of the files in the current directory. 2: removing the specifed file from the list. I have written a sample script ,so can u please verfiy and correct. echo Enter list of files ls *.txt read textfile rm -f... (3 Replies)
Discussion started by: sivaranga001
3 Replies

8. Shell Programming and Scripting

sorting issue

I have files with the name myfile_YYMMDD.txt I need to sort them by their date stamp. I know this will work. ls -lrt * | awk '{print $9}' | cut -d "_" -f3 | sort However, it just returns YYMMDD.txt I can then append the myfile_ to it. However, that myfile_ may change. How do... (1 Reply)
Discussion started by: guessingo
1 Replies

9. Homework & Coursework Questions

Sorting files by size in another directory

1. The problem statement, all variables and given/known data: I'm trying to use a directory path to enter a new directory and sort the files there. I'm using the language C with a system call in Unix to sort the files from smallest to largest. 2. Relevant commands, code, scripts, algorithms:... (1 Reply)
Discussion started by: TedFTW
1 Replies

10. Shell Programming and Scripting

Sorting issue

Hi All, I am working on a huge pile of data. Its about a service initiating a call and and finishing it. The columns that I have is: Date Time URL Call Type ServiceName 5/11/2015 15:00:00 http-/0.0.0.0:8091-9 going to... (3 Replies)
Discussion started by: Junaid Subhani
3 Replies
PAPS(1) 						      General Commands Manual							   PAPS(1)

NAME
paps - UTF-8 to PostScript converter using Pango SYNOPSIS
paps [options] files... DESCRIPTION
paps reads a UTF-8 encoded file and generates a PostScript language rendering of the file. The rendering is done by creating outline curves through the pango ft2 backend. OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. --landscape Landscape output. Default is portrait. --columns=cl Number of columns output. Default is 1. Please notice this option isn't related to the terminal length as in a "80 culums terminal". --font=desc Set the font description. Default is Monospace 12. --rtl Do right to left (RTL) layout. --paper ps Choose paper size. Known paper sizes are legal, letter and A4. Default is A4. Postscript points Each postscript point equals to 1/72 of an inch. 36 points are 1/2 of an inch. --bottom-margin=bm Set bottom margin. Default is 36 postscript points. --top-margin=tm Set top margin. Default is 36 postscript points. --left-margin=lm Set left margin. Default is 36 postscript points. --right-margin=rm Set right margin. Default is 36 postscript points. --gutter-width=gw Set gutter width. Default is 40 postscript points. --help Show summary of options. --header Draw page header for each page. --markup Interpret the text as pango markup. --lpi Set the lines per inch. This determines the line spacing. --cpi Set the characters per inch. This is an alternative method of specifying the font size. --stretch-chars Indicates that characters should be stretched in the y-direction to fill up their vertical space. This is similar to the texttops behaviour. AUTHOR
paps was written by Dov Grobgeld <dov.grobgeld@gmail.com>. This manual page was written by Lior Kaplan <kaplan@debian.org>, for the Debian project (but may be used by others). April 17, 2006 PAPS(1)
All times are GMT -4. The time now is 09:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy