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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove words from file Beeser UNIX for Advanced & Expert Users 5 12-19-2008 12:45 PM
remove first few words from a line shellscripter Shell Programming and Scripting 4 10-08-2008 02:34 AM
read arguments from shell DNAx86 High Level Programming 1 05-11-2008 12:56 PM
Bash Shell - # of arguments DNAx86 Shell Programming and Scripting 1 01-10-2008 01:23 PM
Shell script with arguments sankar6254 Shell Programming and Scripting 3 12-22-2003 09:21 AM

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 02-11-2009
praveenbvarrier praveenbvarrier is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 15
Remove the first two words from shell arguments

Hi
I need to delete first two words from the arguments my script receives .. no matter how many arguments are passed .

Thanks
Praveen
  #2 (permalink)  
Old 02-11-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,904
Code:
shift 2
third=$1
echo $third
should give you your third argument
  #3 (permalink)  
Old 02-11-2009
praveenbvarrier praveenbvarrier is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 15
Hyy , I need all the remaining argument , not only the third , for eg:- if the total arguments are 7 the output shuld be the last 5 arguments .. and if the total argumetns are 10 thn the o/p shuld be 8 .. hope you got my requirements
  #4 (permalink)  
Old 02-11-2009
Whiteboard's Avatar
Whiteboard Whiteboard is offline
Registered User
  
 

Join Date: Feb 2009
Location: @........
Posts: 111
Hope this should help you or else would give u an idea on how to proceed...

echo "one two three four" | cut -d " " -f3-
three four

Please correct me if i understood ur problem in a wrong way.... Also give some sample i/p and o/p so that it will be easy to work on it....
  #5 (permalink)  
Old 02-11-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,904
shift does exactly what you require. "shift 2" deletes the first two arguments from the argument list, eg. $3 becomes $1, $4 becomes $2, etc. If you want to output all your arguments sans the first two, do this
Code:
shift 2
echo "$@"
  #6 (permalink)  
Old 02-11-2009
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Quote:
Originally Posted by praveenbvarrier View Post
Hi
I need to delete first two words from the arguments my script receives .. no matter how many arguments are passed .

Thanks
Praveen
Hey

You can get the count of total arguments being passed. and then you can preserve all of'em except first 2 arguments using for loop.

echo 'num of args: '$#

following for loop will display all the arguments being passed:
for arg in "$@";
do
echo 'arg: '$arg;
done

You can run the while loop 2 less then the count of $#
var=`$# - 2`

you can then run the loop in reverse order, till value of var is achieved.

Hope you got what I am trying to convey.

Thanks
Varun Gupta
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 03:24 PM.


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