Perl : Inline program to determine file size


 
Thread Tools Search this Thread
Top Forums Programming Perl : Inline program to determine file size
# 1  
Old 04-10-2012
Lightbulb Perl : Inline program to determine file size

Hi,

I have 5 files as below

Code:
$ ll sam*
-rw-rw-rw- 1 sam ugroup 0 Mar 21 06:06 sam3
-rw-rw-rw- 1 sam ugroup 0 Apr 3 22:41 sam2
-rw-rw-rw- 1 sam ugroup 17335 Apr 10 06:07 sam1
-rw-rw-rw- 1 sam ugroup 5 Apr 10 07:53 sam5
-rw-rw-rw- 1 sam ugroup 661 Apr 10 08:16 sam4

I want to list out the files that has a filesize greater than 700 bytes
This is the inline code i have written

Code:
$ perl -nwe 'foreach (@ARGV){ print $_ if -s > 700 }' sam*

However i don't get any output on the terminal, can you please tell me what is wrong with this code or if this code is entirely wrong.

Thanks
Sam

Moderator's Comments:
Mod Comment Welcome to the UNIX and Linux Forums. Please use code tags. Video tutorial on how to use them

Last edited by Scrutinizer; 04-10-2012 at 09:44 AM.. Reason: code tags
# 2  
Old 04-10-2012
You don't need '-n' option here.
This User Gave Thanks to yazu For This Post:
# 3  
Old 04-10-2012
Please post the output if the following command:
Code:
perl -e 'printf "%s --> %d\n", $_, -s for @ARGV' sam*

This User Gave Thanks to radoulov For This Post:
# 4  
Old 04-10-2012
@yazu, thanks i got exactly what i was looking for
i used -n option to suppress $_ when i was testing with the code and didn't use foreach, forgot to remove it...

@radoulov, thanks your code gave the below output

Code:
$ perl -e 'printf "%s --> %d\n", $_, -s for @ARGV' sam*
sam1 --> 17335
sam2 --> 0
sam3 --> 0
sam4 --> 661
sam5 --> 5

However I just wanted to get those files greater than a specific size

Moderator's Comments:
Mod Comment Code tags for code, please.

Last edited by Corona688; 04-10-2012 at 12:25 PM..
# 5  
Old 04-10-2012
Does this produce the desired output?

Code:
perl -le'-s > 700 and print for @ARGV' sam*

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 determine Date,TotalFile,total size of file based on date

I have file listed like below -rw-r--r--+ 1 test test 17M Nov 26 14:43 test1.gz -rw-r--r--+ 1 test test 0 Nov 26 14:44 test2.gz -rw-r--r--+ 1 test test 0 Nov 27 10:41 test3.gz -rw-r--r--+ 1 test test 244K Nov 27 10:41 test4.gz -rw-r--r--+ 1 test test 17M Nov 27 10:41 test5.gz I... (5 Replies)
Discussion started by: krish2014
5 Replies

2. Emergency UNIX and Linux Support

Grep inline use perl

Hi, i have input like this : SS-ID VLAN MAC TIME IP RSSI MODE UAPSD BW GI WMOS DHCP IDENTITY ----- ---- --- ---- -- ---- ---- ----- -- -- ---- ---- -------- 1-1 0 C4:46:19:75:C1:55 23m 192.168.5.253 ... (5 Replies)
Discussion started by: justbow
5 Replies

3. Shell Programming and Scripting

Perl inline replace only on 1st line

I have file file_1.out which contains the data below <tr> MAIL # 1 TO src_1 </tr> <tr><td class="hcol">col_id</td> <td class="hcol">test_dt</td> <td class="hcol">user_type</td> <td class="hcol">ct</td></tr> <tr><td class="bcol">1</td> <td class="bcol">2012-09-20</td> <td class="bcol">A</td>... (4 Replies)
Discussion started by: sol_nov
4 Replies

4. UNIX for Dummies Questions & Answers

Determine switch buffer size

Hi everybody, I need to calculate the tcp buffer size of a network switch, since it's not specified in the manual; how do I do this? I have some machines connected to the switch and I can run some socket tests written in C between these machines (I can choose how many bytes to send and... (0 Replies)
Discussion started by: dimpim
0 Replies

5. HP-UX

determine the physical size of the hard disk

Hi is there a cmd in hpux 11 to determine the physical size of the hard disk. not bdf command. i have searched the other threads here but cant find an answer. thank you guys (4 Replies)
Discussion started by: hoffies
4 Replies

6. UNIX for Advanced & Expert Users

How to determine the max file size

Does anyone know a way to determine the maximum filesize on a file system on Solaris, HP-UX, AIX, Linux, and OSF1 using the command line? TIA (2 Replies)
Discussion started by: dknight
2 Replies

7. Programming

In C Program, determine if job is running

Is it possible to run the following Unix command in a C program and obtain results as to whether the job is running or not? ps -ef | grep 'job_name' | grep -v grep I'm fairly new at C and need to know what code I'd need in the C program. Thanks, in advance, for your assistance. (12 Replies)
Discussion started by: BCarlson
12 Replies

8. Shell Programming and Scripting

determine file type with perl

Hello i will like to know please how can i determine file type inside perl script not using the unix "file" program Thanks allot (1 Reply)
Discussion started by: umen
1 Replies

9. Programming

Will exe file size decrease while using inline function

using namespace std; void g(); class A { public : A() { g();g();g(); cout << "Constructor of A"<< endl ;} }; inline void g(){ cout << "vijay" <<endl; } int main() { A a; } when i use inline i get size 303488 Aug 31 12:05 a.out* when not using inline i get size 303572 Aug 31... (1 Reply)
Discussion started by: vijaysabari
1 Replies

10. UNIX for Dummies Questions & Answers

determine the size of a file???

Hello, Can someone please tell me which command to use to determine the size of a file? When I log in to my shell account, I do this $>% ls -als total 632 8 -rw-r--r-- 1 user01 devgrp1 1558 Jul 30 23:25 .kshrc What is "1158"? Bytes? Kilobytes? I apologize if my... (8 Replies)
Discussion started by: alan
8 Replies
Login or Register to Ask a Question