Usage of sed Parameters
Use sed to copy/etc/passwd to/root/test.txt and print all rows with sed.
Print 3 to 10 lines of test.txt
Print the row test.txt contains 'root'
Delete 15 rows of test.txt and all subsequent rows
Delete the line containing 'bash 'from test.txt.
Replace 'root' in test.txt with 'toor'
In test.txt, '/sbin/nologin' is'/bin/login'
Delete all numbers in rows 5 to 10 from test.txt.
Delete all special characters (except numbers and uppercase/lowercase letters) from test.txt)
Place the first and last words in test.txt
Replace the first number and the last word in test.txt
Move the first number in test.txt to the end of the row.
Add 'aaa: 'At the beginning of test.txt 20 rows to the end of the last row :'
My answer:
Sed-n'1, $ 'P test.txt
Sed-n'3, 10' p test.txt
Sed-n'/root/'P test.txt
Sed '15, $ 'd test.txt
Sed '/bash/'d test.txt
Sed-r's/(root)/toor/G'-n test.txt
Sed-r's @ (/sbin/nologin) @/bin/login @ G' test.txt
Sed-r '5, 10 s/[0-9] // G' test.txt
Sed-r's/[^ a-zA-Z0-9] // G' test.txt
Sed-r's @ (^ [^:] +) (:. * :) ([^:] + $) @ \ 3 \ 2 \ 1 @ 'test.txt
Sed-r's @ ([0-9] +) (. * :) ([^:] + $) @ \ 3 \ 2 \ 1 @ 'test.txt
Sed-r's @ ([0-9] +) (. *) ($) @ \ 2 \ 3 \ 1 @ 'test.txt
Sed-r '20, $ s @ (^. * $) @ aaa: \ 1 @ 'test.txt
Introduce shell variable in sed command
Shell programming in Linux -- basic usage of sed command
Sed for Unix text processing tools
Sed advanced usage
Sed command details and examples
This article permanently updates the link address: