valpa 发表于 30-12-2010 14:08:04

add \ to the end of each line

sed "s/\(.*\)/\1 \\\/g" will do the work.

Why need \\\ here. ( three \ char)

coredump 发表于 30-12-2010 14:27:47

I don't think it work, might be:

s/\(.*\)/\1\ \\/g

this first '\' after '\1' is useful for the space, the rest '\\' ouput '\'

李大锤 发表于 30-12-2010 15:53:13

有点绕口吧,可以再简练一些

# cat 1.txt
1 2 3
1 2 3
1 2 3
# sed 's/$/\\/g' 1.txt
1 2 3\
1 2 3\
1 2 3\

coredump 发表于 30-12-2010 15:58:18

回复 #3 李大锤 的帖子

对,你这样写就可以了,最简单,楼主应该是不知道$用作行尾,^用作行首

valpa 发表于 7-1-2011 20:57:17

回复 #3 李大锤 的帖子

明天再给你分,多谢,我一直试啊试啊,就是试不出来
楼下的core,我知道^$, 是最基本的东西

ubuntuhk 发表于 8-1-2011 12:23:06

我不会用sed,一般用awk来实现:cat 1.txt | gawk '{print $0"\\"}'

cfk 发表于 9-1-2011 16:48:30

\\\
第一个是告诉bash第二个\转义,第二个告诉regex engine第三个\转义
页: [1]
查看完整版本: add \ to the end of each line