Strip a string in sh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Strip a string in sh
# 8  
Old 03-23-2010
Hi, LRoberts:

What shell are you using that franklin52's parameter expansion did not work? I'm just curious.

Perharps the following command substitution is good enough:
Code:
/lcl/tools/bin/sshPing.pl "$(echo $remote_server | cut -d: -f1)" > /dev/null

Regards,
Alister
# 9  
Old 03-23-2010
It just does not seem to work. It does not like my syntax.
This is how I am trying it...
Code:
#!/bin/sh
for remote_server in `ypcat osiunix_pods |cut -f 1-2 -d: | sort -t : -k 2`
do
remote=$(remote_server%:*)
/lcl/tools/bin/sshPing.pl $remote > /dev/null


Any ideas?

---------- Post updated at 08:20 AM ---------- Previous update was at 08:17 AM ----------

I tried....
Code:
 /lcl/tools/bin/sshPing.pl "$(echo $remote_server | cut -d: -f1)" > /dev/null

But no luck. using #!/bin/sh
# 10  
Old 03-23-2010
change '#!/bin/sh' to '#!/bin/ksh'
# 11  
Old 03-23-2010
Changed but still does not work... As you can see it still has the whole string...
Now checking for quality connection to: gulfweed.grhq.gfs.com:OES2 ...
# 12  
Old 03-23-2010
Can you post the output of:
Code:
ypcat osiunix_pods

# 13  
Old 03-23-2010
Here is a sample output of....
Code:
ypcat osiunix_pods |cut -f 1-2 -d: | sort -t : -k 2

Code:
greenchromis.grhq.XXX.com:production
guppy.grhq.XXX.com:production
horsehead.grhq.XXX.com:production
jaguar.grhq.XXX.com:production
justy.grhq.XXX.com:production
kraken.grhq.XXX.com:production
leatherback.grhq.XXX.com:production
leviathan.grhq.XXX.com:production
lionhead.grhq.XXX.com:production
mahimahi.grhq.XXX.com:production
mangrove.XXX.com:production
marlin.XXX.com:production
marsh.grhq.XXX.com:production
mg.grhq.XXX.com:production
moccasin.XXX.com:production
molly.grhq.XXX.com:production
moray.grhq.XXX.com:production
odyssey.grhq.XXX.com:production
oscar.grhq.XXX.com:production
penguinshrimp.grhq.XXX.com:production
penribbon.XXX.com:production
rainbowfish.grhq.XXX.com:production
redclawedcrab.grhq.XXX.com:production
ringneck.XXX.com:production
roughgreen.XXX.com:production
sailfish.grhq.XXX.com:production
salmon.can.XXX.com:production
samurai.grhq.XXX.com:production
sandcrab.grhq.XXX.com:production
seaclam.grhq.XXX.com:production
sephia.grhq.XXX.com:production
skimmerclam.grhq.XXX.com:production
snakehead.grhq.XXX.com:production
spikystonecrab.grhq.XXX.com:production
spinychromis.grhq.XXX.com:production
spoonworm.can.XXX.com:production
starfire.grhq.XXX.com:production
steelhead.grhq.XXX.com:production
swordtail.grhq.XXX.com:production
tacoma.grhq.XXX.com:production
tahoe.grhq.XXX.com:production
torino.grhq.XXX.com:production
triggerfish.grhq.XXX.com:production
trumpetsnail.XXX.com:production
unicornfish.XXX.com:production
velvetfish.XXX.com:production
vendace.XXX.com:production
wahoo.grhq.XXX.com:production
walleye.grhq.XXX.com:production
walu.grhq.XXX.com:production
warbonnet.grhq.XXX.com:production
warmouth.grhq.XXX.com:production
wedgeclam.grhq.XXX.com:production
weedfish.grhq.XXX.com:production
weeverfish.grhq.XXX.com:production
yogi.grhq.XXX.com:production
adonistetra.grhq.XXX.com:sit
alewife.grhq.XXX.com:sit
anchovy.grhq.XXX.com:sit
anomura.grhq.XXX.com:sit
arkclam.grhq.XXX.com:sit
asianclam.grhq.XXX.com:sit
awningclam.grhq.XXX.com:sit
badis.grhq.XXX.com:sit
barclam.grhq.XXX.com:sit
barramundi.grhq.XXX.com:sit
beluga.grhq.XXX.com:sit

# 14  
Old 03-23-2010
Try this:
Code:
ypcat osiunix_pods | sort -t : -k 2 | 
while IFS=":" read var dummy
do
  remote=${var%:*}
  /lcl/tools/bin/sshPing.pl $remote > /dev/null
done

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Strip leading and numbers from a string.

Hello I have two vars loaded with $VAR1="ISOMETHING103" $VAR2="COTHERTHING04" I need to: 1) Strip the first char. Could be sed 's/^.//' 2) The number has it's rules. If it has "hundreds", it needs to be striped. If it is just two digits it shouldn't. So, for VAR1 output should be... (7 Replies)
Discussion started by: tristezo2k
7 Replies

2. Shell Programming and Scripting

Strip First few Characters

I want to strip first few characters from each record until a proper datesamp is found. Request for getNextPage.................06/29/12 07:49:30 VVUKOVIC@67.208.166.131{7A805FEF76A62FCBB23EA78B5380EF95.tomcat1}TP-Processor14 LogExchUsage: ERROR:: isprof=false : exch=NSDQ output should be... (2 Replies)
Discussion started by: ratheeshjulk
2 Replies

3. Solaris

strip error

Hi I am getting the below error while using strip command. strip: libelf error. Request error: no string table strip: a.out: file not manipulated Could somebody please let me know what might be the solution?? It is in ksh and solaris 10. Thanks in advance (4 Replies)
Discussion started by: vali__
4 Replies

4. Shell Programming and Scripting

Strip out the string

awk -F"\t" -vOFS="\t" '{print $1"\t-\t-","",$6,$7"\t-"$8"\t-\t-\t"$15}' file.tsv > output.tsv Using the above command how to remove the string www.abc.com from the $7 value. (7 Replies)
Discussion started by: sandy1028
7 Replies

5. Shell Programming and Scripting

How to strip out common terms in string

Hi, I have this kinda of data:- 0,0,0,0,1,2,0,4,5,6,7,foo 0,0,0,0,1,4,0,5,5,5,5,foo1 0,0,6,0,1,6,0,6,1,2,3,orange etc... I wanted to remove the 0 which occur on the same rows of foo,foo1 and orange in this case. Desired output is:- 0,1,2,4,5,6,7,foo 0,1,4,5,5,5,5,foo1... (9 Replies)
Discussion started by: ahjiefreak
9 Replies

6. Programming

Strip command

I am new in Unix. I go through the man strip. But did not understand that, why when we have -G (debug and release ) option in the compiler, than using strip command to strip the debug information from the objects. i want to binary for teh production i will compile it without debug option. What the... (4 Replies)
Discussion started by: Saurabh78
4 Replies

7. Shell Programming and Scripting

Need to strip a string

I have a file that looks like this: /home/fred/opt/bin /opt/usr/bin /usr/sbin/var/opt I need a way to chop of everything after the last occurance of the / sign including the /. So the file above will now look like this below. /home/fred/opt /opt/usr /usr/sbin/var I tried using... (6 Replies)
Discussion started by: x96riley3
6 Replies

8. Shell Programming and Scripting

Strip all non-alphanumerics

Hi, Can someone let me know how do I strip out any non-alphanumeric character in string tomake it alphanumeric? i.e abc def ghi ->abcdefghi abc-def-ghi ->abcdefghi abc#def-ghi->abcdefghi Thanks in advance (3 Replies)
Discussion started by: braindrain
3 Replies

9. Shell Programming and Scripting

How to strip strins

Guys, Please can someone tell me how to strip each string from the following ? TABLE1||METHOD||TYPE||STATUS||DATE What i need is to assign each value to the variable TABLE1 to var1 METHOD to var2 and so on If there is NULL in one of them, something like A||B||||C|| I want the... (14 Replies)
Discussion started by: kamathg
14 Replies
Login or Register to Ask a Question