I have a function which outputs some file paths, I need these paths are separated by NUL charachter instead of new line \n
character. I tried following code:
function myfunc
{
declare -a DUPS
# some commands to fill DUPS with appropriate file/folder paths
( for i in "${DUPS[@]}"; do echo "$i"; done )|sort|uniq|awk 'BEGIN{ORS="\x00";} {print substr($0, index($0, $2))}'
}
But if I pipe its output to hexdump
or hd
, no NUL character is diplayed. It seems that NUL character is not included in the awk
output:
myfunc | hd
Will print:
00000000 2f 70 61 74 68 2f 6e 75 6d 62 65 72 2f 6f 6e 65 |/path/number/one|
00000010 2f 2f 70 61 74 68 2f 6e 75 6d 62 65 72 2f 74 77 |//path/number/tw|
00000020 6f 2f 2f 70 61 74 68 2f 6e 75 6d 62 65 72 2f 74 |o//path/number/t|
00000030 68 72 65 65 2f |hree/|
00000035
My awk
version is:
~$ awk -W version
mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan
compiled limits:
max NF 32767
sprintf buffer 2040
Also any solution with other commands such as sed
is acceptable for me.
NOTE: My question is not duplicate of enter link description here, because it asks for a solution that works on different machines with different awk
s. But I just need a solution that works on my own machine, so I could use any version of awk
that could be installed on Ubuntu 14.04.