Passing an argument to cut command | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Passing an argument to cut command

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-15-2013
bashamsc bashamsc is offline
Registered User
 
Join Date: Feb 2012
Last Activity: 15 February 2013, 5:37 AM EST
Posts: 9
Thanks: 3
Thanked 0 Times in 0 Posts
Passing an argument to cut command

Can we pass an argument to cut command as below

Suppose cut command is used in for or while loop and we need to pass the incremental counter

cut -f$i

Here $i is an argument.

Like wise it has to come

cut -f1
cut -f2

Where i=1,2,3,....
Sponsored Links
    #2  
Old 02-15-2013
Skrynesaver's Avatar
Skrynesaver Skrynesaver is offline Forum Advisor  
Grumpy old geek
 
Join Date: Mar 2011
Last Activity: 23 October 2014, 6:00 AM EDT
Location: Éire
Posts: 821
Thanks: 20
Thanked 185 Times in 181 Posts
As a general rule when wondering if a given construct works, try it and see what happens , (NB: does not apply to potentially destructive commands)


Code:
for i in $(seq 10) ; do echo cut -d\, -f$i tmp.csv ; done
cut -d, -f1 tmp.csv
cut -d, -f2 tmp.csv
cut -d, -f3 tmp.csv
cut -d, -f4 tmp.csv
cut -d, -f5 tmp.csv
cut -d, -f6 tmp.csv
cut -d, -f7 tmp.csv
cut -d, -f8 tmp.csv
cut -d, -f9 tmp.csv
cut -d, -f10 tmp.csv

Looks good to me...
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing argument on find command ajithbe Shell Programming and Scripting 3 11-28-2011 09:13 AM
Passing argument to command in C effizy Programming 3 09-26-2011 11:17 AM
Need Help with the argument passing Through Command line asirohi Shell Programming and Scripting 5 09-04-2009 02:37 AM
passing argument from Cshelll to awk command ganiel24 Shell Programming and Scripting 1 06-24-2009 10:57 AM
passing a command line argument rudoraj Shell Programming and Scripting 8 06-13-2007 11:06 PM



All times are GMT -4. The time now is 06:17 AM.