Linux sed命令操作 删除文件每一行的前k个字符、在文本的行尾或行首添加字符
2017-12-22 14:24
1066 查看
删除文件每一行的前k个字符
$ cat tmp.txt 123456789 123456789 123456789 # 删除每行第一个字符 $ sed 's/.//' tmp.txt 23456789 23456789 23456789 # 删除每行前两个字符 $ sed 's/..//' tmp.txt 3456789 3456789 3456789 # 删除每行前k个字符,例如k=5 $ sed 's/.\{5\}//' tmp.txt 6789 6789 6789
如果要在原文件上修改,加上参数-i就可以了
在文本的行尾或行首添加字符
$ cat tmp.txt 23456789 23456789 23456789 # 在行首添加双引号(") $ cat tmp.txt | sed 's/^/"&/g' "23456789 "23456789 "23456789 # 在行尾添加双引号和逗号(",) $ cat tmp.txt | sed 's/^/"&/g' | sed 's/$/",&/g' "23456789", "23456789", "23456789",
^代表行首,$代表行尾
相关文章推荐
- Linux:用sed命令在文本的行尾或行首添加字符
- Linux shell sed命令在文件行首行尾添加字符
- linux shell 用sed命令在文本的行尾或行首添加字符 - aaronwxb - 博客园
- linux shell 用sed命令在文本的行尾或行首添加字符
- linux shell 用sed命令在文本的行尾或行首添加字符
- linux shell 用sed命令在文本的行尾或行首添加字符
- linux shell 用sed命令在文本的行尾或行首添加字符
- linux shell 用sed命令在文本的行尾或行首添加字符
- 用sed命令在文本的行尾或行首添加字符
- linux shell 用sed命令在文本的行尾或行首添加字符
- 用sed命令在文本的行尾或行首添加字符
- linux shell 用sed命令在文本的行尾或行首添加字符
- linux shell 用sed命令在文本的行尾或行首添加字符
- linux shell 用sed命令在文本的行尾或行首添加字符
- linux shell 用sed命令在文本的行尾或行首添加字符
- linux shell 用sed命令在文本的行尾或行首添加字符
- linux shell 用sed命令在文本的行尾或行首添加字符
- linux shell 用sed命令在文本的行尾或行首添加字符
- linux sed命令在文本的行尾或行首添加字符
- 如何替换某文件中的所有的特定字符?---linux sed命令(文本编辑命令)