I like remove spaces from the beginning and the end of line.
result="$(mysql -r --column-names=0 -e "SELECT String FROM Table")"
echo $result | cat -E
+stringA +StringB $
echo $result | sed 's/^\([[:blank:]]\)\+//g' | sed 's/\([[:blank:]]\)\+$//g' | cat -E
+stringA +StringB $
I copied the string with my mouse, and inserted it with the mouse key 3 (press down the wheel)
echo '+stringA +StringB ' | sed 's/^\([[:blank:]]\)\+//g' | sed 's/\([[:blank:]]\)\+$//g' | cat -E
+stringA +StringB $
now i pressed the key ↑, navigate to the spaces and replace it with del and space
echo '+stringA +StringB ' | sed 's/^\([[:blank:]]\)\+//g' | sed 's/\([[:blank:]]\)\+$//g' | cat -E
+stringA +StringB$
and now the sed command matched and deleted the spaces.
How can i convert wrong spaces non-breaking space to normal spaces?
echo $LANG
en_US.UTF-8
$bash --version
GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu)
mysql -e "SHOW VARIABLES LIKE '%char%'"
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
Update1:
echo '+stringA +stringB ' | od -tx1z
0000000 2b 73 74 72 69 6e 67 41 20 2b 73 74 72 69 6e 67 >+stringA +string<
0000020 42 c2 a0 c2 a0 c2 a0 c2 a0 c2 a0 c2 a0 c2 a0 c2 >B...............<
0000040 a0 c2 a0 0a >....<
0000044
echo '+stringA +stringB ' | od -tx1z
0000000 2b 73 74 72 69 6e 67 41 20 2b 73 74 72 69 6e 67 >+stringA +string<
0000020 42 20 20 20 20 20 20 20 20 20 0a >B .<
0000033
echo '+stringA +stringB ' | od -c
0000000 + s t r i n g A + s t r i n g
0000020 B 302 240 302 240 302 240 302 240 302 240 302 240 302 240 302
0000040 240 302 240 \n
0000044
echo '+stringA +stringB ' | od -c
0000000 + s t r i n g A + s t r i n g
0000020 B \n
0000033
the echo-commands 1 and 3 are copied with mouse key 3
the echo-commands 2 and 4 are with normal spaces
Update2:
i inserted the sedcommand with [^[:graph:]] but it does not change the out.
for UKWID in 123 456 678; do
result="$(mysql -r --column-names=0 -e "SELECT String FROM Table WHERE id = $UKWID")"
echo "$result" | sed 's/^[^[:graph:]]*//;s/[^[:graph:]]*//' | cat -E
done
+stringA +stringB $
+stringc +stringx $
+stringe +stringf $
$resultvar, they are different (i think the encodeing) to normal spaces, which i inserted with my keyboard. There are no visible differ. @RomanPerekhrest