I have file with hex symbols like below
cat demo
\x22count\x22
\x22count\x22
\x22count\x22
I need conversion like:
echo $(cat demo)
"count" "count" "count"
How to get unicode symbols in pipeline with newline symbol? Something like:
cat demo | ???
"count"
"count"
"count"
CodePudding user response:
You could use printf to convert the hexadecimal data. Depending on the size of your input, you could read the lines into an array then use IFS to delimit the output:
join() {
local IFS="$1"
shift
echo "$*"
}
arr=( $(while read -r line; do printf "$line "; done < demo) )
join $' ' "${arr[@]}"
"count" "count" "count"
join $'\n' "${arr[@]}"
"count"
"count"
"count"
CodePudding user response:
You can use printf
's %b
conversion specification. This will print the output you want:
printf '%b\n' "$(<demo)"