The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Dynamically ftp'ing a file pyaranoid UNIX for Advanced & Expert Users 0 09-02-2007 04:34 AM
Moving Part of a field to another field using AWK rjsha1 Shell Programming and Scripting 5 08-04-2006 02:39 AM
dynamically loaded libraries rainshadow High Level Programming 3 06-04-2005 09:31 PM
dynamically linked file sveera UNIX for Advanced & Expert Users 5 06-03-2005 11:52 AM
Dynamically loading a module yanhu High Level Programming 2 04-19-2004 10:07 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 05-19-2008
Registered User
 

Join Date: May 2008
Posts: 51
getting value from field dynamically

how i do pass in field number when cutting, I tried to do this:

Quote:
echo $line|cut -d " " -f`$totalWordOfVessel-1`-$totalWordOfVessel
but it says 11-1: not found
Reply With Quote
Forum Sponsor
  #2  
Old 05-19-2008
agn agn is offline
Registered User
 

Join Date: Feb 2008
Posts: 97
Code:
$ var=1
$ echo $((var+1))
2
$ echo `expr $var + 1`
2
$ echo "$var + 1" | bc 
2
Reply With Quote
  #3  
Old 05-19-2008
Registered User
 

Join Date: May 2008
Posts: 51
it says ranges must be increasing..you mean you can't do a decrement?
Reply With Quote
  #4  
Old 05-19-2008
Registered User
 

Join Date: Aug 2007
Location: Bangalore
Posts: 288
Code:
a=1
b=5
echo $line | tr -s " " | cut -d " " -f$a-$b
Reply With Quote
  #5  
Old 05-19-2008
Registered User
 

Join Date: Jul 2006
Posts: 189
Code:
$ tmp="ABC 123 XYZ 890"
$ t=3
$ echo $tmp | cut -d" "  -f $(echo $t)
XYZ
$ echo $tmp | cut -d" "  -f $(expr $t - 1)
123
$
Reply With Quote
  #6  
Old 05-19-2008
Registered User
 

Join Date: May 2008
Posts: 51
Quote:
Originally Posted by namishtiwari View Post
Code:
a=1
b=5
echo $line | tr -s " " | cut -d " " -f$a-$b
is it possible to do it without using two variables? i want to get last two fields of the line
Reply With Quote
  #7  
Old 05-19-2008
agn agn is offline
Registered User
 

Join Date: Feb 2008
Posts: 97
Code:
echo 'a b c d e f' | cut -d' ' -f 4-
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:49 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0