• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read file contents in loop using shell script

 
Rahul Chaudhari
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18300
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic