Article Title: a collection of practical skills for Linux operating systems. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Because Linux is getting longer and longer, and more things are required, efficiency has become the bottleneck that I must break through. I would like to summarize some of the good Linux skills used during this period. In the future, it will be very convenient to use it as needed.
[Text Processing]
1. View part of a file
If you only want to view the first five lines of the file, you can use the head command,
For example: head-5/etc/passwd
If you want to view the last 10 lines of the file, you can use the tail command,
For example: tail-10/etc/passwd
View the middle part of the file. You can use the sed command
Such as: sed? N'5, 10p'/etc/passwd so that you can only view rows 5th to 10th of the file
2. Change 123 in file.txt to 456.
Method 1
Sed's/123/456/G' file.txt> file.txt. new: Save it to another file.
Sed-I's/123/456/G' file.txt directly modify the original file
Method 2
Vi file.txt
Enter the following command:
: % S/123/456/g
Note: If the replaced file has a special symbol such as/, use \ to cancel it.
Example: sed-I's/\/usr \/local \/apache2 \/htdocs/\/var \/www \/html/G'/usr/local/apache2/conf/ httpd. conf
If you only add the following original row, use &
Example: sed-I's/DirectoryIndex index.html. var/& index.htm index. php/G'/usr/local/apache2/conf/httpd. conf
3. Typical echo applications
Echo "abcdefg" | perl-lne '{$ a = reverse ($ _); print $ a;}' flip a string
Echo bottle | rev flip a string
4. filter out the # header line and all blank lines (useful for viewing configuration documents)
Awk '/^ [^ #]/& amp;/^ [^ $]/' filename> new. file
[1] [2] [3] [4] [5] [6] [7] Next page