Shell Filter displayable characters in bash.

I'm trying to filter out all the displayable characters in a list.

Code:
ch="" #show
ch="֎" #omit
[[ $(fc-list :charset=$(printf %x "'$ch")) ]] && echo $ch

Awk gives an incorrect result.

Code:
printf "%x" \""֎" # correct result 58e
echo -e "֎" | awk '{ system("printf \"%x\" \\\""$0"") }' # false result d6(base) '

# complete script
cat "list" | awk '{split($0, z, ""); for(y=0; y<length(z); y++){ if(system("/usr/bin/fc-list :charset=$(/usr/bin/printf \"%x\" \\\"\""z[y]"\")")){ print z[y] } } }'

thanks for help.
 
Works here:
Code:
$ awk --version
awk version 20210724
$ echo -e "֎" | awk '{ system("printf \"%x\" \\\""$0"") }'
58e%
P.S.
Code:
$ locale
LANG=C.UTF-8
LC_CTYPE="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_TIME="C.UTF-8"
LC_NUMERIC="C.UTF-8"
LC_MONETARY="C.UTF-8"
LC_MESSAGES="C.UTF-8"
LC_ALL=

What's yours?
 
Code:
GNU Awk 5.1.0, API: 3.0 (GNU MPFR 4.1.0, GNU MP 6.2.1)

LANG=de_DE.UTF-8
LANGUAGE=
LC_CTYPE="de_DE.UTF-8"
LC_NUMERIC=de_DE.UTF-8
LC_TIME=de_DE.UTF-8
LC_COLLATE="de_DE.UTF-8"
LC_MONETARY=de_DE.UTF-8
LC_MESSAGES="de_DE.UTF-8"
LC_PAPER=de_DE.UTF-8
LC_NAME=de_DE.UTF-8
LC_ADDRESS=de_DE.UTF-8
LC_TELEPHONE=de_DE.UTF-8
LC_MEASUREMENT=de_DE.UTF-8
LC_IDENTIFICATION=de_DE.UTF-8
LC_ALL=
 
Is there no alternative to get the same in awk?

Code:
# complete script
$ echo -e "\n\n\n"  | awk '{ split($0, z, ""); for(y=0; y<length(z); y++){ if(system("/usr/bin/fc-list :charset=$(/usr/bin/printf \"%x\" \\\"\""z[y]"\")")){ print z[y] } } }'
/usr/bin/printf: '"': expected a numeric value
/usr/share/fonts/truetype/lyx/wasy10.ttf: wasy10:style=LyX
/usr/share/fonts/truetype/lyx/stmary10.ttf: stmary10:style=LyX
/usr/bin/printf: warning: ��: character(s) following character constant have been ignored
/usr/share/fonts/truetype/lato/Lato-Medium.ttf: Lato,Lato Medium:style=Medium,Regular
# ...  wrong

# How can it be the same result like that?
$ for z in $(echo -e "\n\n\n"); do
[[ $(fc-list :charset=$(printf %x "\"$z")) ]] && echo "$z"
done

 # correct
 
Last edited:
Back
Top