jQuery in Action, 2nd edition*
The moose likes Linux / UNIX and the fly likes How to read last line from multiple files and redirect it into a single file using Linus script. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "How to read last line from multiple files and redirect it into a single file using Linus script." Watch "How to read last line from multiple files and redirect it into a single file using Linus script." New topic
Author

How to read last line from multiple files and redirect it into a single file using Linus script.

Ashwin Kumar Balasubramanian
Greenhorn

Joined: Aug 03, 2012
Posts: 5
Hi Friends,
I got a folder named Server_logs. Inside that there are 20 files named in following way.

data_log_192.168.27.1.log
data_log_192.168.27.2.log........ so on till
.
.
.
data_log_192.168.27.19.log

These files differ only from their IP address. I want to open up each file and read only the last line from these files. the last line has the following information " 129G 39G 84G 32% /data ". and redirect these data's from other files into a single file.
Can anyone write a script and give me please. Am totally new to Linux and am not getting the proper code to write.
Please Help..!!
Anand Hariharan
Rancher

Joined: Aug 22, 2006
Posts: 257

Doing a or should help.

Try

hope this helps,
- Anand

"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19



Note that the "ls" command is quoted using back-tick characters, not normal (apostrophe) single-quite characters. The difference is critical.

An alternative notation might be "$(( ls Server_logs/*.log ))", but without actually trying it I'm not sure.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to read last line from multiple files and redirect it into a single file using Linus script.
 
Similar Threads
Need help for Shell Script to reduce a file
Array Index out of range issue
Search on a string
mysql database restore
I want my ant script Implement a function