简体   繁体   中英

Counting lines with non-printable characters with BSD

I am trying to sort out some bad data in a file on a BSD-style system, which means that I do not have the -P option in grep. I have 7 million lines of data, and a subset has some strange characters. If you to a "less" on the file, you'll see something like this:

290437430@89
9^@0333465@88
290348389@87
290342818@8^@

The ^@ is from a bad character that is not ASCII that showed up due to noise on the serial line when the characters were sent. These lines are corrupt, and I want to count the number of corrupt data strings.

Any suggestions would be greatly appreciated.

As per Chepner's suggestion adding following solution here:

grep -c '\x00' Input_file

Following 2 will give only literal characters only.

If you want to only count @ then a simple grep could help you on same.

grep -c "@"  Input_file

Or in case of counting ^@ then following may help you on same.

grep -c "\^@"  Input_file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM