Sunday, January 01, 2012
How to create a file from which the vi editor reads commands - Linux
To create a file from which the vi editor reads commands:
1) Use the vi editor to create and then save the file testfile containing the following text
This is line 1.
This is line 2.
This is line 3.
This is line 4.
2) Type cat testfile and press ENTER to check your work.
3)Next, using the vi editor, create and save another text file named commands with one line containing the following vi commands: 2GddGp:x
4) Type cat commands and press ENTER to verify the contents of the commands file.
5) Type vi testfile < commands and press ENTER. (Because the input is from a file and not the keyboard, you might see a warning that the input is not from a terminal. Simply ignore the warning.) This loads testfile into the vi editor and redirects vi's input to the text in the command file. The text in the commands file is treated as commands typed on the keyboard.
6) Type cat testfile and press ENTER. You see the contents of testfile after the vi commands execute. The contents are:
This is line 1.
This is line 2.
This is line 3.
This is line 4.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment