Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of sed under Unix (1)

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Sed usage: sed 'Command' filename (s) displays only the results without modifying the file.

1. Sed '2j5d' file displays the file file, excluding 2-5 lines, but there will be no error when the number of lines exceeds the actual number of lines of the file.

Sed'/ 10 [1-4] / d 'file displays the file file, removing the lines containing 101104.

Sed'2 file displays the file, showing only the first line. Sed'2 recorded file displays only the lines except the first line.

Sed'/ ^ * $/ d file removes blank lines from the file.

2. Sed-n'/ 10 [1-4] / p 'file shows only the lines in the file file that contain 101104. (- n and p must be used at the same time, otherwise only p displays all files and lines found one more time.)

Sed-n'5p 'file shows only the fifth line of the file

3. Sed's change modling, mod _ file, and replace moding with moden.

4. Sed-n's / ^ west / north/p' file replaces the line at the beginning of west with north and displays it.

5. Sed's / [0-9] [0-9] [0-9] $/ & .5 / 'file replaces the line ending with three numbers in the file file with the original number plus ".5", and & represents the searched string.

6. Sed's /\ (mod\) ing/\ 1en/g file encapsulates mod as mode 1 in parentheses, and then replaces it.

Sed's /... $/ / 'file deletes the last three characters of each line.

Sed's / ^... / / 'file deletes the first three characters of each line.

7. Sed's replacing modulated file with the # after moden,s represents the delimiter between the search string and the replacement string.

8. Sed-n'/ 101According to the matching line from 101to 105According to 105Universe p' file. If only the matching line of 101 is found, then from the matching line of 101 to the end of the file.

Sed-n'2 Magneto 999max p 'file shows from the second line to the matching line.

9. Sed'/ 101 file will add "20050119" content from the matching line of 101to the end of the matching line of 105Compact.

10. Sed-e '1Magi 3d'-e's stop modulation file delete 1-3 lines of the file first, then replace it.

Sed-e'/ ^ # /! d 'file displays the lines where the file begins with #.

11. Sed'/ 101 newfile' file adds the contents of the file newfile to each matching line

The sed'/ 101 outside newfile' file writes matching lines to the newfile.

12. Sed'/ 101 Compact a\

> # 'file adds a new line after matching the row.

Sed'/ 101 Compact I\

> # 'file adds a new line before matching the row.

Sed'/ 101 Compact c\

> # 'file replaces matching lines with new lines.

13. Sed'Compact ABCD file replace a, b, c, d with ABCD, respectively.

14. Sed '5q' file exits when line 5 is displayed.

15. Sed'/ 101 / {n; s _ file _

Sed'/ 101 / {sqqq; 'file finds the first matching line in the file, replaces it, and then exits.

16. Sed-e'/ 101 / {h; d;}'- e'/ 104 / {G;} 'file finds matching lines in the file and stores them in a cache, and then puts them in a cache.

Sed-e'/ 101 / {h; d;}'- e'/ 104 / {g;} 'file finds matching lines in the file and then replaces 104matching lines in a cache.

Sed-e'/ 101 bind h'-e'$G' file places the last matching line at the end of the file.

Sed-e'/ 101 bind h'-e'$g 'file replaces the last line of the file with the last matching line.

Sed-e'/ 101Compact h'-e'/ 104Universe file find matching lines in the file and store them in a cache, then swap them with 104matching lines.

17. Sed-f sfile file operates according to the command list of the file sfile.

Cat sfile

/ 101plana\

# 101.

* 101m / s *

/ 104Universe c\

# 104 deleted####\

* 104 deleted****

1I\

# test####\

* test****

For the oracle video tutorial, please follow: http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report