|
Home > Archive > Unix Programming > June 2004 > how to pass a variable to 'cut' to represent a column
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
how to pass a variable to 'cut' to represent a column
|
|
| Ryan Gaffuri 2004-06-16, 5:57 pm |
| Not sure if this got posted already, if so please ignore...
I want to pass a variable to represent the column I want to 'cut', the
following returns the whole line.
CUT_FIELD=2
RETURN_VALUE=`grep ^${GREP_NAME} $FILE_NAME|cut -f${CUT_FIELD} -d:`
DATA:
GREP_NAME HELLO GOODBYE 1
In this case, I only want to return "GOODBYE", however, I in the
future I may want to return "HELLO" or "1"
| |
| Alex Sisson 2004-06-17, 5:55 pm |
| rgaffuri@cox.net (Ryan Gaffuri) wrote in message news:<1efdad5b.0406160612.6f3aa12b@posting.google.com>...
> Not sure if this got posted already, if so please ignore...
>
> I want to pass a variable to represent the column I want to 'cut', the
> following returns the whole line.
>
> CUT_FIELD=2
> RETURN_VALUE=`grep ^${GREP_NAME} $FILE_NAME|cut -f${CUT_FIELD} -d:`
>
> DATA:
> GREP_NAME HELLO GOODBYE 1
>
> In this case, I only want to return "GOODBYE", however, I in the
> future I may want to return "HELLO" or "1"
why are you delimiting by comma?
awk maybe easier....try piping it though awk \{print\$$CUT_FIELD\}
|
|
|
|
|