Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Skipping every other parameter

Status
Not open for further replies.

PistolPete1999

Technical User
Jan 14, 2003
3
0
0
US
How do i skip every other parameter? like for example

REVERSEM K B Z D E K "G," M O

it should display O G, E Z and skips the first two parameters

*REVERSEM is the name of the script

i got the first two parametrs removed working but struggled with skipping every other parameter


A=$*
B=""

shift 2

for i in $A
do
B="$i $B"
done
echo $B

Any help would be appreciated
 
first purge ", then print it:
echo "K B Z D E K \"G,\" M O" | sed -e 's/"//;s/\([A-Z]\) \([A-Z]\) \([A-Z]\) \([A-Z]\) \([A-Z]\) \([A-Z]\) \([A-Z],\) \([A-Z]\) \([A-Z]\)/\9 \7 \5 \3/'



-----------
Ohne Intelligenz bist Du ein Fiasko,
ohne Technik ein Amateur und
ohne Herz eine Maschine.

[ Wladimir Horowitz ]
 
Hi,
you can do:
#!/bin/ksh
i=$#
while [ $i -gt 2 ]
do
B=$B" "$(($i))
((i=i-2))
done
echo $B
Regards Boris
 
Hey Boris,

thanks for replying, its a good script but when i changed the $# to $*, i got a msg saying too many arguements and i noticed that ure using KORN, im using bash, unless im wrong, they re different right?

Any Solutions?

Thanks
 
#!/bin/ksh

#str='K B Z D E K "G," M O'

typeset -i iter=${#}

while [ ${iter} -gt 2 ]
do
eval "printf \"\${$iter} \" "
iter=$((iter-2))
done
echo
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hey Fellas,

finally figured the right code for this...

#!/bin/sh
clear
shift 2

last=$#

while [ $last -gt 0 ]
do
eval 'v=\$$last&quot;
echo -n &quot;$v&quot;
last=$(($last-2))
done
echo




thanks to those people who tried to help out :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top