wood burning stoves 2.0*
The moose likes Linux / UNIX and the fly likes Read file contents in loop using shell script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Read file contents in loop using shell script" Watch "Read file contents in loop using shell script" New topic
Author

Read file contents in loop using shell script

Rahul Chaudhari
Greenhorn

Joined: Jul 30, 2008
Posts: 5
Hi
I have one log file which containt output of ls command. I want to read that file content and get the file name and size then I have to check that if that file size is zero then touch that file locally other wise get that file from ftp.

log file contents are(FileName is filelist.txt):

unknown security mechanism
unknown security mechanism
Passive mode off.
-rwxr----- 1 smartscm System 761 Jun 18 2008 APPayment20080618123001.csv
-rwxr----- 1 smartscm System 0 Jun 19 2008 APPayment20080619123000.csv
-rwxr----- 1 smartscm System 0 Jun 25 2008 APPayment20080625123001.csv
-rwxr----- 1 smartscm System 1961 Jun 30 2008 APPayment20080630123001.csv

How i can read the filename and size?
I want to read filename in loop so I can check the size condition and get the file from FTP accd. to condition.

Thanks....
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15957
    
  19

The awk utility is good for this. So are a number of other common system scripting utilities, including raw script programming and perl, but in this case, the awk solution is probably the simplest. You'd just set up a pattern to match only the "ls" output lines and then use awk's builtin field-parsing abilities to extract the values.


Customer surveys are for companies who didn't pay proper attention to begin with.
Mirko Bonasorte
Ranch Hand

Joined: May 14, 2007
Posts: 244
The script accepts the file name as first argument.
It supposes that:
1. All the files are named *.csv
2. All the fields are splitted with a whitespace


[ July 31, 2008: Message edited by: Mirko Bonasorte ]

SCJP<br />SCWCD 1.4 Upgrade (Remember: me stupid)<br />SCWCD 1.4<br /><a href="http://jcp.org/aboutJava/communityprocess/final/jsr220/index.html" target="_blank" rel="nofollow">SCBCD 5.0</a><br /><a href="http://www.enthuware.com" target="_blank" rel="nofollow">SCBCD 5.0 mock exam</a> <br /> <br />SCEA 5 Part1: Preparing...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Read file contents in loop using shell script
 
Similar Threads
IO PerformanceTuning - How to read entire contents from a .csv File without using loop(while/do/for)
How to upload file to ftp in java
How to download csv file
read large CSV file and update the database
problem with if-condition