Review
extension
- print line to line content http://ask.apelearn.com/question/559
# sed -n '/特定字符/,/特定字符/'p test.txt
- sed convert case http://ask.apelearn.com/question/7758
- In sed, use \u for uppercase and \l for lowercase
- Capitalize the first lowercase letter of each word:
# sed 's/\b[a-z]/\u&/g' filename
- Convert all lowercase to uppercase:
# sed 's/[a-z]/\u&/g' filename
- Uppercase to lowercase:
# sed 's/[A-Z]/\l&/g' filename
- sed adds a number at the end of a line http://ask.apelearn.com/question/288
# sed 's/(^指定字符.*)/\1 数字/' test.txt
# sed 's/(^指定字符.*)/& 数字/' test.txt
# sed '/^指定字符/s/$/ 数字/' test.txt
- Delete a line to the last line http://ask.apelearn.com/question/213
Delete the matching line and the next line of the matching line# sed '/指定字符/{p;:a;N;$!ba;d}' test.txt 定义一个标签a,匹配c,然后N把下一行加到模式空间里,匹配最后一行时,才退出标签循环,然后命令d,把这个模式空间里的内容全部清除。 if 匹配"c" :a 追加下一行 if 不匹配"$" goto a 最后退出循环,d命令删除。
sed -i '/sample/{N;d}' filename
//sample is the matching character, N here is the next line, d is the delete - Print 1 to 100 lines containing a string http://ask.apelearn.com/question/1048
# sed -n '1,100{/sample/p}' 1.txt