Jun 7, 2007 #1 jtanner Technical User Joined Feb 18, 2007 Messages 39 Location US Hello, In a Bourne shell script I have a variable length string that is enclosed in parenthesis. Examples Code: echo "$CONN1" (2msec) echo "$CONN2" (10msec) echo "$CONN3" (100msec) How can I get ride of the parenthesis? Thanks, JT
Hello, In a Bourne shell script I have a variable length string that is enclosed in parenthesis. Examples Code: echo "$CONN1" (2msec) echo "$CONN2" (10msec) echo "$CONN3" (100msec) How can I get ride of the parenthesis? Thanks, JT
Jun 7, 2007 #2 aigles Technical User Joined Sep 20, 2001 Messages 464 Location FR You can use tr : Code: echo "$CONN1" | tr -d '()' Jean-Pierre. Upvote 0 Downvote
Jun 7, 2007 #3 sbrews Technical User Joined Jun 11, 2003 Messages 413 Location US I'm assuming that (2msec) is what is contained in variable CONN1. Based on that assumption, this will remove the parens: Code: CONN1=`echo $CONN1| tr -d '()'` echo $CONN1 2msec Add a little color to your PUTTY terminal: faq52-6627 Upvote 0 Downvote
I'm assuming that (2msec) is what is contained in variable CONN1. Based on that assumption, this will remove the parens: Code: CONN1=`echo $CONN1| tr -d '()'` echo $CONN1 2msec Add a little color to your PUTTY terminal: faq52-6627
Jun 7, 2007 #4 sbrews Technical User Joined Jun 11, 2003 Messages 413 Location US It appears that aigles is faster on the keyboard than me. Add a little color to your PUTTY terminal: faq52-6627 Upvote 0 Downvote
It appears that aigles is faster on the keyboard than me. Add a little color to your PUTTY terminal: faq52-6627
Jun 7, 2007 #5 PHV MIS Joined Nov 8, 2002 Messages 53,708 Location FR The good old legacy Bourne shell... what about this ? Code: expr "$CONN1" : '(\(.*\))' Hope This Helps, PH. FAQ219-2884 FAQ181-2886 Upvote 0 Downvote
The good old legacy Bourne shell... what about this ? Code: expr "$CONN1" : '(\(.*\))' Hope This Helps, PH. FAQ219-2884 FAQ181-2886
Jun 7, 2007 #6 p5wizard IS-IT--Management Joined Apr 18, 2005 Messages 3,165 Location BE With sed: Code: CONN1=$(echo "${CONN1}"|sed 's/[()]//g') or Code: CONN1=`echo "${CONN1}"|sed 's/[()]//g'` HTH, p5wizard Upvote 0 Downvote
With sed: Code: CONN1=$(echo "${CONN1}"|sed 's/[()]//g') or Code: CONN1=`echo "${CONN1}"|sed 's/[()]//g'` HTH, p5wizard
Jun 8, 2007 Thread starter #7 jtanner Technical User Joined Feb 18, 2007 Messages 39 Location US Guys, All your suggestions were simple and brilliant. Thanks, JT Upvote 0 Downvote
Jun 8, 2007 #8 p5wizard IS-IT--Management Joined Apr 18, 2005 Messages 3,165 Location BE Here's a less "simple" solution ;-): Code: CONN1=$(echo "${CONN1}"|fold -w1|grep -v '('|grep -v ')'|tr -d '\n') HTH, p5wizard Upvote 0 Downvote
Here's a less "simple" solution ;-): Code: CONN1=$(echo "${CONN1}"|fold -w1|grep -v '('|grep -v ')'|tr -d '\n') HTH, p5wizard