Hazim
Hazim

Reputation: 381

What is ^X in in Linux?

For my homework assignment, I have to make sure that my output matches the solution output 100% or I don't get credit.

My output is:

hw05-data-10.txt : min = 5, max = 90, mean = 51.23, variance = 618.34

The solution output is:

hw05-data-10.txt : min = 5, max = 90, mean = 51.23, variance = 618.34

They look similar, however when I use diff mine.txt solution.txt, I get a difference.

I used cat -tev mine.txt and cat -tev solution.txt to find the difference, and I found that mine looks like:

hw05-data-10.txt^X : min = 5, max = 90, mean = 51.23, variance = 618.34$

and the solution looks like:

hw05-data-10.txt : min = 5, max = 90, mean = 51.23, variance = 618.34$

What is ^X? I've tried looking around but I can't find the answer. How can I remove this from my output? It's a C program.

Upvotes: 1

Views: 8336

Answers (3)

Luis Colorado
Luis Colorado

Reputation: 12668

^X is ASCII CAN, cancel control character. Normally it is not used by the linux tty driver on output, so you will not see it when output to the terminal. If you use it on input, linux tty driver will interpret it as the STOP character and will send a SIGSTOP signal to the foreground process, causing it to stop execution until it receives a SIGSTART signal. The character you mention is probably somewhat inserted in the format string you used for the printf(3) call. (you have not shown your code snippet in the question)

The ^X character is also used in some window environments to Cut the selected text, so probably you inserted it at some undesired place in the program source code.

Upvotes: 0

paxdiablo
paxdiablo

Reputation: 881563

^X is the CTRL-X character, made visible by the -v flag of cat.

If you want to get rid of it, you can pass the contents through something like:

tr -d '[:cntrl:]'

See the following transcript for an example (the ^X is inserted in bash with CTRL-VCTRL-X):

pax> echo '123^X456' | cat -v
123^X456

pax> echo '123^X456' | tr -d '[:cntrl:]' | cat -v
123456

If you want to remove it at the source rather than filtering after the event, you need to investigate the program that's creating your mine.txt file. It will be the one inserting the rogue character.

Upvotes: 1

Raptor
Raptor

Reputation: 54212

According to the man page of cat command,

-v flag: Display non-printing characters so they are visible. Control characters print as ^X for control-X; the delete character (octal 0177) prints as ^?. Non-ASCII characters (with the high bit set) are printed as M- (for meta) followed by the character for the low 7 bits

-e flag: Display non-printing characters (see the -v option), and display a dollar sign (`$') at the end of each line.

Therefore, the answer of ^X is a Control Character. To remove from output, remove the -v and -e flag from your cat command if possible. If can't, you have to investigate your C program: why it's generating this control character.

Upvotes: 0

Related Questions