How to print part of a line PART 2

Using Groovy, I wish to grab two parts of a tab-separated line. Take the example line:

one fish two fish red fish blue fish ----(each character tab /t separated)

Suppose I want to print one and then I want to print red fish blue

How can I do this?

Alternatively, suppose I want to print one and then a count of the number of characters (words) following red? Or between two and blue?

A previous question yielded this response for printing everything following a certain part of the line:

c = ~/.*red(.*)/

m = line =~ c
if (m) {
println m[0][1]

to yield fish blue fish but I'm not comptetent enough with regex's to modify this appropriately. I've tried a few iterations, inserting /t in there and modifying my capturing expression but I've not figured it out. This is three or four questions in one, any help is appreciated. Thanks!!


def a = [:].withDefault{[]}
def b = [:].withDefault{[]}
def c = 0
def d = 0
def e = 0
def f = 0

seuss = "one\tfish\ttwo\tfish\tred\tfish\tblue\tfish"
a = seuss.split (/\t/)

for (i =0; i<a.size(); i++) {
 if (d != 0) {
    c = c + 1
if ( a[i] == "red") {
    d = i


println a[4] + '\t' + c

for (i =0; i<a.size(); i++) {
if ( a[i] == "blue") {
    e = 0
 if (e != 0) {
    f = f + 1
if ( a[i] == "two") {
    e = i


println a[0] + '\t' + f

Need Your Help

C++ Can't compare dereferenced char pointer to char

c++ string xcode6

I have an input string, and I want to find how many spaces are there in the string.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.