vic
vic

Reputation: 400

Grep: Issue with null byte

I have the following command in a bash script.

GREP_RESULT=$(grep -zoP "\.global LIST(.|\n)*-1\Z" part1.s)

I'm getting the following error.

warning: command substitution: ignored null byte in input

I have tried the solution proposed in this post, changing it to the following.

GREP_RESULT=$(tr -d '\0' < grep -zoP "\.global LIST(.|\n)*-1\Z" part1.s)

This in turn results to the following error.

grep: No such file or directory

What is the proper way to work around the first error?

Upvotes: 1

Views: 527

Answers (1)

markp-fuso
markp-fuso

Reputation: 34214

UPDATE:

Comment from OP: grep -z is adding a \0 on end of stream

So, this is a case of needing to modify the grep output (as opposed to modifying the input file):

grep -zoP "\.global LIST(.|\n)*-1\Z" part1.s | tr -d '\0'

Original answer ...

Apply the tr to the data file first; a couple variations:

grep -zoP "\.global LIST(.|\n)*-1\Z" <(tr -d '\0' < part1.s)

# or 

tr -d '\0' < part1.s | grep -zoP "\.global LIST(.|\n)*-1\Z"

Upvotes: 2

Related Questions