Substring of string in tag + shell script
Hi,
Please help me solve the following as I am new to scripting I have a string variable var1=<default>111</default> I want the value between default tags 111 in this case. I treid to use ${var1:10:3} But the execution gived "bad substitution' error. If the tags are removed and substring is fetched it works fine. Please help me. Is there any other was to get substring in a string with tags. Thanks i advance |
Indexing is zerobased, so it should be ${var:9:3}. Otherwise it works on my bash shell.
|
You need quotes to assign the string:
Code:
c:~$ var1=<default>111</default> Code:
c:~$ var1='<default>111</default>' |
Quotes are needed indeed!
|
Thanks for ur reply...
Can you please tell me a way to extract 111 from <default>111</default> using SED command. I do not want to hard code the character position to get the value. |
Quote:
|
All times are GMT -5. The time now is 09:40 AM. |