Listing files in a particular format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Listing files in a particular format
# 8  
Old 08-23-2011
Hi,

I think I have clearly stated my requirements. But if still required the output to make the things more clear, I am posting it as below--

Right now my output is like below-

Code:
ll | awk ' !/^d/ { if(NR>1) {printf "%-29s\t\t%s\t%5s\t\t%s %s,%s\n", $9,$1,$5,$6,$7,$8} }'

a.out                                   -rw-------          0           Aug 5,06:55
dir_str.txt                             -rw-------         35           Aug 19,10:23
dont_make_test                          ----------          0           Aug 23,10:03
get_dir_stru.sh                         -rwx------        599           Aug 5,11:02
mm                                      -rwx------         85           Aug 23,09:34

But he output I want should be like this
Code:
a.out                                   600          0           Aug 5, 2011
dir_str.txt                             600         35           Aug 19, 2011
dont_make_test                          000          0           Aug 23, 2011
get_dir_stru.sh                         700        599           Aug 5, 2011
mm                                      700         85           Aug 23, 2011

And I am sorry Panyam that I mentioned "creation time", yes it's modification time.

Thanks.
# 9  
Old 08-23-2011
Hello,

I'm sorry but I was not much helpful. I searched few things in the forum and found this below useful.

Code:
 
#!/usr/bin/ksh
typeset -Z2 d m
Jan=1 Feb=2 Mar=3 Apr=4 May=5 Jun=6 Jul=7 Aug=8 Sep=9 Oct=10 Nov=11 Dec=12
date "+%Y %m" | read year month
for i in `ls -l|awk '!/^d/{print $NF}` ; do
        line=$(ls -dl $i)
        line=${line##+([! ])+([ ])}
        line=${line##+([! ])+([ ])}
        line=${line##+([! ])+([ ])}
        line=${line##+([! ])+([ ])}
        line=${line##+([! ])+([ ])}
        set -A stamp $line
        d=${stamp[1]}
        eval m=\$${stamp[0]}
        y=${stamp[2]}
        ((${#y} != 4)) && ((y=year-(m>month)))
        echo $i ${stamp[0]} $d","$y
done
exit 0

You might need to figure it out on how to add file permissions and other fields to the output as required.

Last edited by panyam; 08-23-2011 at 12:32 PM.. Reason: added to get only files
# 10  
Old 08-23-2011
Hi Panyam,

I forget to mention, my shell is 'sh', so will the code given by you will work on that shell?

Thanks,
Manu
# 11  
Old 08-23-2011
Try this and see if returns the desired output:

Code:
ll|awk -v "year=`date '+%Y'`" '$8!~":"{if(NR>1)printf"%-29s\t\t%s\t%5s\t\t%s %s,%s\n", $9,$1,$5,$6,$7,$8} {if(NR>1)printf"%-29s\t\t%s\t%5s\t\t%s %s,%s\n",  $9,$1,$5,$6,$7, year}'

This User Gave Thanks to dude2cool For This Post:
# 12  
Old 08-23-2011
Hehe,

This is not the exact solution. I am not that much efficient in Unix coding. But by seeing your code, I came to know, that you have searched : in $8 parameter and if it not found, then you printed $8 as it is (as it will be already a year format) and if its found, you replaced $8 with current year (that is WRONG, we need to compare the months as well in that case, if month of file modification is greater than the current month of the current year, then we need to do year=year-1 else year=year). How this will help you (eventually me Smilie ) to write a code for that.

I appreciate your efforts. But whatever you have done can be done by the code below as well--

Code:
ll | awk -v "yr=`date '+%Y'`" ' !/^d/ { if(NR>1) {printf "%-29s\t\t%s\t%5s\t\t%s %s,", $9,$1,$5,$6,$7}; if(index($8,":")==3) { print yr } else { print $8 
} }'

Thanks.

Last edited by manubatham20; 08-23-2011 at 02:52 PM..
# 13  
Old 08-23-2011
Can you past a line from ls that you think the awk code will not work against? i.e paste a line from your ls output where "month of file modification is greater than the current month of the current year"? Maybe I can modify the logic.
# 14  
Old 08-23-2011
Well, for that I need to change the date/time of the system, for that privilidges not granted to me.

Just set your system date to '29-Dec-2010', make a file, now again set your date to '2-Jan-2011', now execute your command. Let me know if your code work perfectly.

Regards,
Manu

---------- Post updated 08-24-11 at 01:16 AM ---------- Previous update was 08-23-11 at 10:28 PM ----------

Code:
#!/bin/sh
ll | awk -v "yr=`date '+%Y'`" -v "mnth=`date '+%m'`" 'BEGIN { split("Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec", MON, "|"); for(N=1; N<=12; N++) I[MON[N]]=N; } !/^d/ { if(NR>1) {printf "%-29s\t\t%s\t%5s\t\t%s %s,", $9,$1,$5,$6,$7}; if(index($8,":")==3) { if(I[$6]>mnth) { print yr-1 } else { print yr }} else { print $8 } }'

The above has fulfilled my purpose.

Thanks all for your time and support.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to generate HTML output format listing like orasnap

Hi, Is there any UNIX scripts out there that generates a listing output of some sort similar to OraSnap At the moment, I have a script that I run on multiple servers that has multiple databases and just querying the database sizes of those databases. It generates a text files that contains... (0 Replies)
Discussion started by: newbie_01
0 Replies

2. Shell Programming and Scripting

Listing the file name and no of records in each files for the files created on a specific day

Hi, I want to display the file names and the record count for the files in the 2nd column for the files created today. i have written the below command which is listing the file names. but while piping the above command to the wc -l command its not working for me. ls -l... (5 Replies)
Discussion started by: Showdown
5 Replies

3. UNIX for Dummies Questions & Answers

How to find directory listing from root to all files in tree format with details of perm/own/grp?

Hi, My apologies if my query is already available on this forum but I am new and could not find. I need a script to list all directories/sub directories and files with permissions/groups/owners. The script would run from home directory and should capture every directory. How do I do this? ... (4 Replies)
Discussion started by: 8709711
4 Replies

4. Shell Programming and Scripting

Need script for transferring bulk files from one format to text format

"Help Me" Need script for transferring bulk files from one format to text format in a unix server. Please suggest (2 Replies)
Discussion started by: Kranthi Kumar
2 Replies

5. Shell Programming and Scripting

modify ls -l (long listing format output) strictly using SED only straightforward goalhard 4 me doh

Below is a sample out of ls -l which I would like to rearrange or modify by field numbers for example I successfully managed to disect using simple paragraph however for ls -l I can't divide the rows or fields by field number. Successful modification by fields using SED sample: $ sed -e... (1 Reply)
Discussion started by: wolf@=NK
1 Replies

6. Shell Programming and Scripting

perl script for listing files and mailing the all files

Hi, I am new to perl: I need to write perl script to list all the files present in directory and mail should be come to my inbox with all the files present in that directory. advanced thanks for valuable inputs. Thanks Prakash GR (1 Reply)
Discussion started by: prakash.gr
1 Replies

7. UNIX for Advanced & Expert Users

listing files excluding files from control file

I have a directory named Project.I have a control file which contains valid list of files.I would like list the files from directory Project which contains files other than listed in the control file. Sample control file: TEST SEND SFFFILE CONTL The directory contains followign... (15 Replies)
Discussion started by: ukatru
15 Replies

8. Shell Programming and Scripting

listing file with other format

Hello. If i use ls to list file, the output will be like this: ls list* list1.txt list2.txt list3.txt list4.txt list5.txt How can I list file like below (I tried to us ls -ltr list*.txt, but all of them with time, date in font of the file...but I don't need it)? list1.txt... (3 Replies)
Discussion started by: happyv
3 Replies

9. Shell Programming and Scripting

Listing filesnames in bare format with fullpath

Hi, Need help. How can I get a listing of files in bare format with full path. I mean in the following format. /root/dir1/sub-dir1/file1 /root/dir1/sub-dir1/file2 /root/dir1/sub-dir2/file1 /root/dir1/sub-dir2/file2 /root/dir2/sub-dir1/file1 /root/dir2/sub-dir2/file1... (2 Replies)
Discussion started by: tipsy
2 Replies

10. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies
Login or Register to Ask a Question