Remove the first two words from shell arguments


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove the first two words from shell arguments
# 1  
Old 02-11-2009
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  
Old 02-11-2009
Code:
shift 2
third=$1
echo $third

should give you your third argument
# 3  
Old 02-11-2009
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  
Old 02-11-2009
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  
Old 02-11-2009
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  
Old 02-11-2009
Quote:
Originally Posted by praveenbvarrier
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
Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove last few words from Line

Hi I would like to remove last few words from File Could anybody Help on it. ps -ef | grep mgr.prm | awk '{print $10}' /opt/app/dummyd/xyz/dirprm/mgr.prm /opt/app/dummy/xyz/dirprm/mgr.prm /opt/app/dummy/xyz/dirprm/mgr.prm I want output like /opt/app/dummyd/xyz... (4 Replies)
Discussion started by: tapia
4 Replies

2. Shell Programming and Scripting

Remove very first pair of duplicate words

I have file which is almost look like below MMIT MMIT ... (2 Replies)
Discussion started by: manas_ranjan
2 Replies

3. Shell Programming and Scripting

remove words

All, I have a file with below entries. /java/usr/abc/123 /java/usr/xyz/123_21 /java/usr/ab12/345/234 ......... ......... And I need entry as /java/usr/abc/config /java/usr/xyz/config /java/usr/ab12/config ......... ......... Actually, I need to remove all other entries... (2 Replies)
Discussion started by: anshu ranjan
2 Replies

4. Shell Programming and Scripting

Perl to remove words between patterns

Hi, I am using following code to remove words between start and end points. $mystring = "The start text always precedes the end of the end text."; if($mystring =~ s/start(.*)end/\0/) { print $1; print "\n"; print $mystring; } But this is writing special chars in place of... (1 Reply)
Discussion started by: sarbjit
1 Replies

5. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

6. Shell Programming and Scripting

Need to remove the words

Hi folks, I have file with the below 1245633505 +manual mroennfeldt@news.com.au 1245633506 +manual sal@bynews.com.au 1245633506 +manual whson@btimes.com 1245633507 +manual karla.marsden@tnews.com.au 1245633508 +manual king@netn.com.au Now, I need the output of the files only with... (4 Replies)
Discussion started by: gsiva
4 Replies

7. Shell Programming and Scripting

how to remove words between /* and */ in several lines of file

hi, I want to remove comments in somany files. coments started from /* and ends with */. so i wnt to remove words /* to */ how to remove words between /* and */ in several lines of file EX : cat haha.txt "HI",/*hk*/ob1,raju,/*hjh*/boju,beeju output should be : "HI",ob1,raju,boju,beeju ... (8 Replies)
Discussion started by: spc432
8 Replies

8. Shell Programming and Scripting

Remove arguments

Hi all, First of all, this is my first post in this forum, so it's nice to know you. I hope not to brake any 'rule' ;) I'd like to know, if it's possible to remove a parameter from command line, regardless of its position? I've found a solution using shift, if it's the first argument. But, I... (6 Replies)
Discussion started by: AlbertGM
6 Replies

9. UNIX for Advanced & Expert Users

Remove words from file

Hello, I have a question: I have two different files, let's call them file1 and file2. file1 contains a list of words, the words are on seperate lines: word1 word2 word3 word4 etc... file2 also contains a list of words, seperated in the same way as file1. What I want to do is... (5 Replies)
Discussion started by: Beeser
5 Replies

10. Shell Programming and Scripting

remove first few words from a line

Hi All, Sample: 4051 Oct 4 10:03:36 AM 2008: TEST: end of testcase Checking Interface after reload, result fail I need to remove first 10 words of the above line and output should be like Checking Interface after reload, result fail Please help me in this regard. Thanks, (4 Replies)
Discussion started by: shellscripter
4 Replies
Login or Register to Ask a Question