To get one part of a string
Hi,
I am trying to compare 2 strings and get the numbers not present in string 2 but are PRESENT in string 1. var2 = total no. var3 = part of the same string i want var 5 to be part of var2 which is not in var3. echo "total no :"$var2 var3=`echo $var2 | awk '{ print substr( $0, length($0) - 9, length($0) ) }' ` echo "contact no :"$var3 var5=`echo $var2 | awk '{ print substr( $var2-$var3 ) }' ` echo "isd code :"$var5 -- IM NOT SURE ABOUT HOW TO GO ABOUT THIS... Please help |
Hi,
I'm not sure if I understood correctly, but does the following little python script do what you want? Code:
#!/usr/bin/python Evo2. |
This version is a little more compact.
Code:
#!/usr/bin/python |
err.. the idea was to get the isd code from the entire mobile number.
var2 has the entire number . var3=`echo $var2 | awk '{ print substr( $0, length($0) - 9, length($0) ) }' ` echo "contact no :"$var3 and in Var3 - i get the 10 digits starting from the RHS. (backwards) the rest will be the ISD code ( which i want in var5).. but i am not able to get output for var 5. var5 is where i need help to extract. var5=`echo $var2 | awk '{ print substr( $var2-$var3 ) }' ` echo "isd code :"$var5 what should i change in var5? |
Could you please show us an actual example or two of the text stored in both variables, and what you want from them?
I have a feeling that you are making this much more complicated than it needs to be. I'm betting that you can probably do what you want with a simple parameter substitution or two, or some other form of built-in string manipulation. But as a first bit of advice, $(..) is highly recommended over `..`. Backticks are generally deprecated. And please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques. Edit: As a concept example, assuming bash, and assuming that you want to simply remove the last ten digits from the number: Code:
$ var=1234567890987654321 Code:
$ echo "${var%??????????}" |
Hi,
Quote:
Quote:
Code:
a="xxyyzz00112233445566778899" |
Code:
$ echo "${var%${var:(-10)}}" Thanks David,evo2 - yes i was wrong and making it more complicated than it actually is. And ill make sure to follow those rules before posting. |
All times are GMT -5. The time now is 01:20 AM. |