DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Cut Blank(s) Separated Fields In Text File On Windows

08.24.2011
| 1947 views |
  • submit to reddit
        The code (!) :
echo @ruby -ne "puts $_.split(/\s+/)[%1].join(' ')" > rcut.bat

When a file look like :

127.0.0.1 -  -  [16/ao¹t/2011:23:40:15 +0000] "GET / HTTP/1.1" 200 673 "-" "Ruby"
127.0.0.1 -  -  [16/ao¹t/2011:23:42:25 +0000] "GET / HTTP/1.1" 200 673 "-" "Ruby"
. . . . 

Then we can do :
> find "10.177.235" request.log | rcut 0..4
10.177.235.213 - - [24/ao¹t/2011:14:11:19 +0000]
10.177.235.213 - - [24/ao¹t/2011:14:11:19 +0000]
10.177.235.177 - - [24/ao¹t/2011:14:27:28 +0000]
10.177.235.177 - - [24/ao¹t/2011:14:27:28 +0000]
10.177.235.177 - - [24/ao¹t/2011:14:27:28 +0000]