New to linux, practising bash on a VM running Ubuntu through VirtualBox. Have a command to print the first character of each line in a text file which produces correct output:
cut -f 1- -d "^M" sample.txt | cut -c 1
However when i copy command from terminal and paste back into terminal using Ctrl+Shift+c and Crtl+Shift+v then execute, it gives me the following error:
cut: the delimiter must be a single character
Edit: I type "^M" by holding Ctrl+v and hitting Carriage Return
Edit: Didn't realise Cut command operates on each line anyway, so first part of command in example given is useless, even so question remains valid.
The only case I know in Linux where you get ^M
on your screen typing ctrlv followed by Enter is inside the text editor vim or gvim.
In that case, the text entered in your file is really a carriage return, but on the screen, you see the two characters ^M
. Since what you see is not what you get, copying and pasting it will lead to unpredictible results.
In Linux, the lines are not separated by carriage returns (hexadecimal code 0d
or ctrlm), but by line feeds (hexadecimal code 0a
or ctrlj).