From: Robert Klemme Date: 2004-03-06T22:39:40+09:00 Subject: Re: Ruby translation for UNIX scripting command "Thomas Luedeke" schrieb im Newsbeitrag news:20040305181503.955C3B6CC@xprdmailfe14.nwk.excite.com... > > > > > > > > > Quick (and slightly embarassing) newbie question for the Ruby experts. I'm trying to learn Ruby, and move away from antediluvian UNIX scripting.How do I make a sequence of pattern matching lines in a file, then extract a particular field from the line? For example, in UNIX talk if I were interested in finding all lines with a particular match pattern "test", and printing the fourth field, I'd do a grep plus awk command such as:grep "test" file_name | awk ' { print $4 } ' >> output_fileHowever, in my Ruby books, I don't see any discussion about the function equivalent of printing a field of the type "$4" (i.e. fourth field). I can get the lines out of the search file, but I'm not quite sure how to determine fields.Thanks.TPL $> ruby -a -n -e 'puts $F[3] if /test/' test-file.txt If you need to split with another pattern, do $> ruby -a '-F\s+' -n -e 'puts $F[3] if /test/' test-file.txt Regards robert