• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Read file contents in loop using shell script

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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....
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic