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
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.
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.
-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.
Why not:
while read -r line; do echo -e $line; done < at.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With