The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk parameter alokmits Shell Programming and Scripting 5 01-30-2008 03:10 AM
how do I make dynamic parameter names? Or get the value of a parameter evaluated twi Awanka Shell Programming and Scripting 2 04-19-2007 10:37 PM
parameter u263066 Shell Programming and Scripting 5 10-12-2006 04:46 AM
Assign value to a variable in a parameter file gopskrish Shell Programming and Scripting 2 06-22-2005 08:26 AM
How to check parameter variable? negixx Shell Programming and Scripting 4 06-10-2005 06:37 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-31-2007
Knotty Knotty is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 11
Can a variable be used as a cut fieldname parameter?

Hi,

Is it possible to use a variable as a fieldname parameter for the cut command. I am trying to extract fields from a variable. Say that I want to cut the fields 1,3,5,7,9, etc, but I don't know how many fields that the variable will have i.e. could be 100 or more. I thought that I could use a variable var and then use the command cut -f$var -d' ' in a loop structure and increment the variable but it seems that this is not possible.

Any suggestions?
  #2 (permalink)  
Old 03-31-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398

Code:
echo $var | cut -d' ' -f1,3,5,7,9

  #3 (permalink)  
Old 03-31-2007
Knotty Knotty is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 11
but what if I need more fields depending on the number of fields in the variable?
  #4 (permalink)  
Old 03-31-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398

Code:
$ x="1,2,5,8"
$ echo "a|b|c|d|e|f|g|h|i|j|k|l" | cut -d"|" -f$x
a|b|e|h

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:56 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0