【学习笔记】linux bash script

1. sed


 sed 是一种流编辑器,它是文本处理中非常常用的工具,能够完美的配合正则表达式使用,功能非常强大。

mkdir playground

touch test.txt

echo "Hello world!" >> test.txt

cat>test.txt<<EOF

> i love you

> my honey

> be easy

> last row

> EOF

例如:

删除文档的第一行

sed -i '1d' test.txt

cat test.txt
my honey
be easy
last row
test.txt

删除文档的第三行

sed -i '3d' test.txt

cat test.txt
my honey
be easy
test.txt

删除文档的最后一行

sed -i '$d' test.txt

cat test.txt
my honey
test.txt

未完待续……

猜你喜欢

转载自www.cnblogs.com/phillee/p/10789243.html
今日推荐