0

zfs diff replaces some of the characters in files names with \xxxx (in an octal encoding). Can I decrypt it back with awk or sed or any other common utility (without resorting to a perl or a python script)? An example zfs diff output can be created as follows:

echo '+ F /dir/my\0040file' > listing

My question is, can I decrypt listing to get

+ F /dir/my file

instead of

+ F /dir/my\0040file

(My ultimate goal is to pipe it back in ls -l to get file sizes.)

6
  • Have you checked whether zfs diff has an option to return the raw filenames instead of escaping it?
    – Barmar
    Oct 4, 2020 at 9:53
  • @Barmar According to the man page, it does not.
    – Andrei
    Oct 4, 2020 at 10:00
  • Add -e to your echo command? See: help echo
    – Cyrus
    Oct 4, 2020 at 10:08
  • @Cyrus, ah sorry. I might not have been clear in my question. I used echo just to make an example listing. In practice, that would be an output of a zfs diff command. So, I have listing just as given and I cannot create it in a different way.
    – Andrei
    Oct 4, 2020 at 10:17
  • Please add sample output from zfs diff (no descriptions, no images, no links) and your desired output for that sample to your question (no comment).
    – Cyrus
    Oct 4, 2020 at 10:26

2 Answers 2

1

Using GNU awk since strtonum():

$ echo '+ F /dir/my\0040file' | 
awk '{
    while(match($0,/\\0[0-9]{3}/)) {               # find \nnnn 
        c=strtonum(substr($0,RSTART+1,RLENGTH-1))  # extract the nnnn
        printf "%s%c",substr($0,1,RSTART-1),c      # output
        $0=substr($0,RSTART+RLENGTH)               # prepare for next round
    }
    print $0
}'

Output:

+ F /dir/my file

Pretty much tested only on your sample.

1

This might work for you (GNU sed and dash):

sed 's/.*/echo "&"/e' file

N.B. The version I use evaluates the RHS of the substitution command using /bin/sh which points to dash. The command echo in dash converts \0nnn to its octal representation.

1
  • I guess you meant sed 's/.*/echo -e "&"/e' file?
    – Andrei
    Oct 7, 2020 at 17:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .