Cat special characters meaning

cat

with cat, I use the -A flag and I can't find what these characters mean anywhere. For example:

cat /proc/cpuinfo > output

cat -A output

One of the lines is this:

processor^I: 7$

I know the $ means new line, but what does ^I mean?

What does ^@ mean?

I'm trying to figure out what type of white space cpuinfo spits out so I can strip them in my C program, but I'm having a difficult time doing that.

Best Answer

^I and ^@ use the common “caret” notation for control characters. ^I means the ASCII character control-I, i.e. character 9, which is a tab. ^@ means the ASCII character control-@, i.e. character 0, which in C is the string end character. The general form is ^c where c is an uppercase letter or one of @[\]^_, representing the byte whose value is that of c minus 64; and ^? representing the byte value 127 (which is the byte value of ? plus 64).

There's another, far less standard notation used by cat -A: non-ASCII bytes (i.e. byte values 128 and above) are shown as M- followed by the representation of the byte whose value is 128 by less (i.e. the byte value with the upper bit flipped).

cat -A isn't the best way to understand visually ambiguous output. A hexadecimal transcript gives you more precise information, e.g.

od -t x1 /proc/cpuinfo
hd /proc/cpuinfo

But from a C program you can just use scanf to parse the information. All ASCII whitespace is whitespace to scanf, and with files in /proc you know that the format will be valid.

Related Question