filter file size and file name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting filter file size and file name
# 1  
Old 02-22-2012
Network filter file size and file name

I want to filter file information so that i have a column containing file size adjacent to a column containing that files name.

I am using:
Code:
find . -type f -exec ls -l {} \; | awk '$5 $9 {print $5 $9}'

and the problem lies with $9 because it prints the file path, /. . ./filename.
I want the filename to print not the file path.

Last edited by Franklin52; 02-22-2012 at 05:47 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 02-22-2012
Remove the unwanted strings using awk function sub
Code:
find . -type f -exec ls -l {} \; | awk '{sub(/.*\//,"",$9);print $5,$9}'

This User Gave Thanks to michaelrozar17 For This Post:
# 3  
Old 02-22-2012
Code:
#!/usr/ksh

echo `find . -type f -exec ls -l {} \; | awk '$5 {print $5}'` > file_size
echo `find . -type f -exec basename {} \; | awk '$9 {print $9}'` > file_name

while read -A file_Size
do
        while read -A file_Name
        do
                for #incomplete for loop
                echo ${file_Size[i]} ${file_Name[i]}
                let "i = i + 1"
        done < file_name

done < file_size

---------- Post updated at 02:28 AM ---------- Previous update was at 02:04 AM ----------

Code:
#!/usr/ksh

echo `find . -type f -exec ls -l {} \; | awk '$5 {print $5}'` > file_size
echo `find . -type f -exec basename {} \;` > file_name
i=0
while read -A file_Size
do
        while read -A file_Name
        do
                while [ i -lt ${#file_Name[*]} ]
                do
                        echo ${file_Size[i]} ${file_Name[i]} 
                        let "i = i + 1"
                done
        done < file_name
done < file_size


Last edited by Franklin52; 02-22-2012 at 05:48 AM.. Reason: Please use code tags for code and data samples, thank you
# 4  
Old 02-22-2012
Hi Robin,

Pls try this using sed and awk:

Code:
find . -type f -exec ls -1 {} \; | sed 's/\(.*\)\///g' | xargs ls -l | awk '{print $4,$8;}'

Code:
find . -type f -exec ls -l {} \; |nawk '{gsub(/.*\//,"",$8);print $4,$8}'

thanks,
Shanmu
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to filter file using range in another file

I have a very large tab-delimited, ~2GB file2 that I am trying to filter using $2 of file1. If $2 of file1 is in the range of $2 and $3 in file1 then the entire line of file2 is outputed. If the range match is not found then that line is skipped. The awk below does run but no output results. ... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Shell script to filter records in a zip file that contains matching columns from another file

Not sure if this is the correct forum for this question. I have two files. file1.zip, file2 Input: file1.zip col1, col2 , col3 a , b , 0:0:0:0:0:c436:9346:d40b x, y, 0:0:0:0:0:880:39f9:c9a7 m, n , 0:0:0:0:0:80c7:9161:fe00 file2.txt col1 c4:36:93:46:d4:0b... (1 Reply)
Discussion started by: anil.v
1 Replies

3. UNIX for Dummies Questions & Answers

Filter records in a huge text file from a filter text file

Hi Folks, I have a text file with lots of rows with duplicates in the first column, i want to filter out records based on filter columns in a different filter text file. bash scripting is what i need. Data.txt Name OrderID Quantity Sam 123 300 Jay 342 498 Kev 78 2500 Sam 420 50 Vic 10... (3 Replies)
Discussion started by: tech_frk
3 Replies

4. Shell Programming and Scripting

Filter a .kml file (xml) with data set from text file

I have a .kml file. So I want filter the .kml to get only the tags that have this numeric codes that they are in a text file 11951 11952 74014 11964 11965 11969 11970 11971 11972 60149 74018 74023 86378 11976 11980 11983 11984 11987 (5 Replies)
Discussion started by: pcoj33
5 Replies

5. Shell Programming and Scripting

The scripts not able to make the file to size 0, every times it go back to its original size

#!/bin/sh ########################################################################################################## #This script is being used for AOK application for cleaning up the .out files and zip it under logs directory. # IBM # Created #For pdocap201/pdoca202 .out files for AOK #1.... (0 Replies)
Discussion started by: mridul10_crj
0 Replies

6. Shell Programming and Scripting

filter record from a file reading another file

Hi, I want to filter record from a file if the records in the second column matches the data in another file. I tried the below awk command but it filters the records in the filter file. I want the opposite, to include only the records in the filter file. I tried this: awk -F'|'... (8 Replies)
Discussion started by: gpaulose
8 Replies

7. Shell Programming and Scripting

Filter the file list greater then the size specified by user

HI, Can any tell me how to filter the list of files greater than the size specified by user. The size should be provided by user as an input. Regards shiva (6 Replies)
Discussion started by: shivu
6 Replies

8. Shell Programming and Scripting

file size comparision local file and remote file

Hi, I have written a script which would FTP a dump file to the FTP server and log the whole activity into a file. to confirm the success of the file copy i grep for "226 file receive OK" and then send out an email saying success. Now i want to make sure the bytes of the local file and... (4 Replies)
Discussion started by: dba.admin2008
4 Replies

9. UNIX for Dummies Questions & Answers

Using input file to filter data from another file

I have a data file: abc Text Text Text Unique Text 123 Text word Line Unique Text fgh Text data Line Unique Text 789 Text Text Line Unique Text 543 Text Text Data Unique Text and a filter file 123 789 I want to extract out from the data file the two records that contain the keys... (1 Reply)
Discussion started by: tumblez
1 Replies

10. Solaris

command to find out total size of a specific file size (spread over the server)

hi all, in my server there are some specific application files which are spread through out the server... these are spread in folders..sub-folders..chid folders... please help me, how can i find the total size of these specific files in the server... (3 Replies)
Discussion started by: abhinov
3 Replies
Login or Register to Ask a Question