View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

Match row number

sw wrote on Apr 15, 2008

Hi.

Does anyone know of a task that is similar to match, but outputs a row/column number instead of just printing the line? I've been searching around but to no avail.

Thank you!!

Mike Fitzpatrick wrote on Apr 15, 2008

The unix 'grep command with a '-n' flag will print the line number, but there's no way to get the column. If by 'column' you mean a column in a table and not just the position in a line of text, then piping the grep to an awk command might work.

-Mike

sw wrote on Apr 15, 2008

Thanks Mike, I didn't know grep worked within IRAF - thought match was there as its equivalent. You were correct in assuming I meant columns as in a table. It just so happens that the column I'm after is always the first one so I think the row number will suffice.

Doing a "grep -n WORD FILE" works out fine, but do you know how I'd go about sticking it in a script? Is that possible?

Sorry to keep bugging you!

Thanks,

Sam

Mike Fitzpatrick wrote on Apr 15, 2008

Doing a "grep -n WORD FILE" works out fine, but do you know how I'd go about sticking it in a script? Is that possible?


Grep is declared (along with many others) as a foreign command in your login.cl file. You can extend the list of available commands by editing that file or simply using the '!' shell escape.

To answer your specific question: For foreign commands you simply use the "program mode" syntax, i.e.

grep ("-n", "word", "file.txt")


where cmdline args like '-n' become literal arguments, and filenames like 'file.txt' could just as easily be script variables. If grep wasn't a foreign command you'd just create the command string and pipe it to the CL, e.g.

print ("!grep -n myword " // fname) | cl()


-Mike

sw wrote on Apr 15, 2008

That's all making a lot of sense. Thank you for your time - it's very much appreciated.

Last post on Apr 15, 2008