how to pass a variable to 'cut' to represent a column
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > how to pass a variable to 'cut' to represent a column




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    how to pass a variable to 'cut' to represent a column  
Ryan Gaffuri


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-16-04 10: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"





[ Post a follow-up to this message ]



    Re: how to pass a variable to 'cut' to represent a column  
Alex Sisson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
06-17-04 10: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\}





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:21 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register