Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make 'cat' in Linux to interpret control characters

Consider the following echo command:

 echo -e "at\r"

which produces the output at on the command line, i.e. the \r special character has been interpreted. I want to do the exact same thing with some text in a file. Supposing the exact same sequence

at\r

is written to a file named at.txt, then I want to display it on the terminal. But

cat at.txt

gives the output

at\r

what is not what I want. I want the special sequence \r to be interpreted, not just printed on the terminal. Anyone any idea?

Thanks Alex

like image 314
Alex Avatar asked Aug 29 '12 09:08

Alex


People also ask

How do you show control characters in Unix?

To look for any control character Both grep and sed can search for a complemented character class/range, which will find lines containing any character that is not a 'printable' (graphic or space) ASCII character.

What is output of cat file text?

cat sends its output to stdout (standard output), which is usually the terminal screen. However, you can redirect this output to a file using the shell redirection symbol ">". For instance, this command: cat mytext.txt > newfile.txt.

What does cat V do?

-v option in the cat command is used to show the non-printing characters in the output. This option become useful when we are suspecting the CRLF ending lines, in that case it will show ^M at the end of each line.


1 Answers

Why not:

while read -r line; do echo -e $line; done < at.txt
like image 122
Stephane Rouberol Avatar answered Oct 11 '22 19:10

Stephane Rouberol