Linux Operations Learning-eighth Day-linux Text tool sed with vim (vi)

Source: Internet
Author: User
Tags egrep

Overview:

In this article, we mainly study two powerful text editors to understand the characteristics of the two text editors.

A, VI (VIM) text editor

Exercises and after-school assignments

1. Delete all whitespace characters from the beginning of lines in the/etc/grub2.conf file that begin with whitespace

Sed "s/^[[:space:]]\+//"/etc/grub2.cfg
Sed-r "s/^[[:space:]]+//"/etc/grub2.cfg

2. Delete all # and white space characters at the beginning of the line beginning with #, followed by at least one white-space character, in the/etc/fstab file

Sed-r "s/^#[[:space:]]+//"/etc/fstab
Sed "s/^#[[:space:]]\+//"/etc/fstab

3. Add # At the beginning of each line of/root/install.log

Sed-r "s/^.*/#&/"/root/install.log
Sed-r "s/(. *) @#\1/g"/root/install.log
Sed "s/^/#/"/root/install.log

4. Add # to the beginning of the line in the/etc/fstab file that does not begin with #

Sed-r "s/^[^#]/#&/"/etc/fstab

5, processing/etc/fstab path, use sed command to take out its directory name and base name

Echo/etc/fstab | Sed-r "s/^\/.*\<//" #基名
Echo/etc/fstab | Sed-r "s/([^/]+\/?) $//"#目录名
echo "/ETC/FST/SD" | Sed-r ' s/(. */) ([^/]+/?) $/\1/' #基名用 \2 directory name \1

6. Use SED to remove the IPv4 address of the ifconfig command

Ifconfig | Sed-n "2p" |sed-r "s/^[^:]+\://" | Sed-r "s/[[:space:]].*//"
Ifconfig|sed-n 2p |sed-r ' s/.*addr: (. *) bca.*/\1/'
Ifconfig|sed-n 2p |sed-e ' s/.*addr://'-e ' s/b.*//'
Ifconfig|sed-n 2p |sed-r ' s/.*addr: (. *) bca.*/\1/'

7. Statistics of all RPM files in the package directory on the CentOS installation CD. Number of repetitions of the second-to-last field

CentOS6.8

ls/media/centos_6.8_final/packages/*.rpm |egrep-o "[^.] +.rpm$ "|egrep-o" ^[^. +\> "
ls/media/centos_6.8_final/packages/*.rpm |sed-r "s/\.rpm$//" | Sed-r "s/.*\<//"

CentOS7.2

Ls/run/media/root/centos\ 7\ x86_64/packages/*.rpm |egrep-o "[^.] +.rpm$ "|egrep-o" ^[^. +\> "
Ls/run/media/root/centos\ 7\ x86_64/packages/*.rpm |sed-r "s/\.rpm$//" | Sed-r "s/.*\<//"

8. How do I set the tab indent to 4 characters?

Vim ~/.vimrcset tabstop=4 #tabstop =tssource ~/.VIMRC

To enhance the contrast, we can set the value of the TabStop to 16, comparing the effects of both

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/85/A7/wKioL1erIrbgNiBIAABhnoVOoJc392.jpg "style=" float: none; "title=" set.jpg "alt=" Wkiol1erirbgnibiaabhnovoojc392.jpg "/>

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M02/85/A8/wKiom1erIreBBCwYAABauUJHpJA679.jpg "style=" float: none; "title=" tab4.jpg "alt=" Wkiom1erirebbcwyaabauujhpja679.jpg "/>

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M02/85/A7/wKioL1erIrjSLOfZAABwJsFhqlo583.jpg "style=" float: none; "title=" tab16.jpg "alt=" Wkiol1erirjslofzaabwjsfhqlo583.jpg "/>

9. Copy the/etc/rc.d/init.d/functions file to/tmp directory, replace the/etc/sysconfig/init in the/tmp/functions file with/var/log;

Cp/etc/rc.d/init.d/functions/tmpvim/tmp/functions

After opening the file with VIM, Shift-click: Key from Command mode (edit mode) into insert mode (input mode)

Input%[email protected]/etc/sysconfig/[email protected]/var/[email protected] Enter

Go in again. Insert mode (input mode)

Enter Wq Save and exit

10. Delete the # at the beginning of all lines in the/tmp/functions file that begin with # and have at least one blank character after #;

Vim/tmp/functions

After opening the file with VIM, Shift-click: Key from Command mode (edit mode) into insert mode (input mode)

Input%[email protected]^#\ ([[: Space:]]\+.*\) @\[email protected] Enter

Go in again. Insert mode (input mode)

Enter Wq Save and exit



Not to be continued

This article is from the "Autumn Wind Night Rain" blog, please be sure to keep this source http://2849159106.blog.51cto.com/7881853/1836613

Linux Operations Learning-eighth Day-linux Text tool sed with vim (vi)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.