Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Passing an argument to cut command

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 02-15-2013
Skrynesaver's Unix or Linux Image
Skrynesaver Skrynesaver is offline Forum Advisor  
Grumpy old geek
 
Join Date: Mar 2011
Last Activity: 5 February 2016, 9:54 AM EST
Location: Éire
Posts: 900
Thanks: 23
Thanked 210 Times in 206 Posts
As a general rule when wondering if a given construct works, try it and see what happens Linux , (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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 10:13 AM
Passing argument to command in C effizy Programming 3 09-26-2011 12:17 PM
Need Help with the argument passing Through Command line asirohi Shell Programming and Scripting 5 09-04-2009 03:37 AM
passing argument from Cshelll to awk command ganiel24 Shell Programming and Scripting 1 06-24-2009 11:57 AM
passing a command line argument rudoraj Shell Programming and Scripting 8 06-14-2007 12:06 AM



All times are GMT -4. The time now is 10:09 PM.