I have a NUL delimited output coming from the following command :
some commands | grep -i -c -w -Z 'some regex'
The output consists of records of the format :
[file name]\0[pattern count]\0
I want to use text manipulation tools, such as sed/awk, to change the records to the following format :
[file name]:[pattern count]\0
But it seems that sed/awk usually handles only records delimited by the "newline" character. I would like to know that how sed/awk could be used to achieve my purpose, or if sed/awk could not handle such case what other Linux tool should I use.
Thanks for any suggestion.
Lawrence
Since version 4.2.2, GNU sed
has the -z
or --null-data
option to do exactly this. Eg:
sed -z 's/old/new' null_separated_infile