viko
March 10, 2008, 2:11pm
1
hi there
I'm getting a string from a sqlplus query, and I need to compare it with another string
Problem here, is that the string i get from query brings a 'carriage return' with it, and comparing throws always false value.
i need to delete all carriage retun charactres in string.
how can i do that?
regards
VIKO
give an exampel from your file... if there is a ^M at the end of each line you can use the "dos2unix" command for example.
Or:
sed 's/^M$//' file > newfile
Press Ctrl-V then Ctrl-M toget ^M in the sed command.
Regards
viko
March 10, 2008, 3:24pm
4
i get string from a sql query, so it's in a variable: $string
i can't see carriage return any time in variable, because echo $string does no print these. and i'm not sure i'm talking about a CR.
but i'm sure something is in there, because if i try
var1='
reply'
and then i try
if [ $var1 == 'reply' ]; then
this returns false value. but again, i'm not sure if a carriage return is inside the variable.
i was trying with
${string/^M/}
but no changes.
viko
March 11, 2008, 2:14pm
5
well.
i made it, and just to help anyone eho needs something like this:
i have made something like:
dirty_var='
something'
var="$(echo $dirty_var | grep some_char_u_know_exists_in_var)"
for checking:
bash-2.05$ if [ "$dirty_var" == "something" ]; then echo OK; fi
bash-2.05$ if [ "$(echo $dirty_var | grep some)" == "something" ]; then echo OK; fi
OK
bash-2.05$
regards
VIKO
viko:
i get string from a sql query, so it's in a variable: $string
i can't see carriage return any time in variable, because echo $string does no print these. and i'm not sure i'm talking about a CR.
<snip>
If you pipe the line(s) to "od -c" you will be able to "see" the special characters (\t for tabs, etc.). That should help you make a more precise fix.
Example:
cat file.txt | od -c
viko
March 13, 2008, 8:08am
7
Thanks
that's very usefull for me
regards
VIKKKO