In order to insert output of a command while in Vim
editor. Just give following command.
:r !any_command
Replace any_commandwith the command you want to use.
22
23
Suppose we want insert date at line number 23,
goto line number 23, by pressingG23
Then type following command
:r !date
22
23 Sat May 9 20:15:56 IST 2009
Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts
Saturday, May 9, 2009
Read Command Output in Vim
Monday, March 31, 2008
Convert DOS EOL (End of Line) to Linux EOL
This is useful when you do not have dos2unix command.
You can determine whether a file is having DOS End of Line.
$ od -c dos_file.txt | grep "\\\r" | wc -l
If you see any output other than 0, then this file
is having \r\n as new line (i.e DOS EOL).
1. Suppose you want to convert EOL of dos_file.txt . Open this
file using vim as:
$ vim dos_file.txt
2. If ^M (Ctrl-M) character is at end of every line, then this file
is in DOS format. We have to remove this ^M from the end
of line. Therefore, go to Edit mode by pressing Esc (Escape
button).
3. Type
:%s/^M$//g
And viola!, you will find that all ^M has gone from end of line.
4. Now, save the file and exit.
PS. In order to type ^M on screen, you should press Ctrl-v Ctrl-m
Otherwise this method will not work.
Alternatively, you can use sed to remove ^M from end of line, given
as following:
$ sed 's/^M$//g' dos_file.txt > temp
$ mv temp dos_file.txt
You can determine whether a file is having DOS End of Line.
$ od -c dos_file.txt | grep "\\\r" | wc -l
If you see any output other than 0, then this file
is having \r\n as new line (i.e DOS EOL).
1. Suppose you want to convert EOL of dos_file.txt . Open this
file using vim as:
$ vim dos_file.txt
2. If ^M (Ctrl-M) character is at end of every line, then this file
is in DOS format. We have to remove this ^M from the end
of line. Therefore, go to Edit mode by pressing Esc (Escape
button).
3. Type
:%s/^M$//g
And viola!, you will find that all ^M has gone from end of line.
4. Now, save the file and exit.
PS. In order to type ^M on screen, you should press Ctrl-v Ctrl-m
Otherwise this method will not work.
Alternatively, you can use sed to remove ^M from end of line, given
as following:
$ sed 's/^M$//g' dos_file.txt > temp
$ mv temp dos_file.txt
Subscribe to:
Posts (Atom)
