解析线延续字符的最简单方法是什么?这似乎是这样一个基本的行动,我很惊讶没有这样做的基本命令。 'while read'和'while read -r'循环没有做我想做的事情,我发现的最简单的解决方案就是下面的sed解决方案。有没有办法做到这一点,像tr一样的基本?解析线延续
$ cat input Output should be \ one line with a '\' character. $ while read l; do echo $l; done < input Output should be one line with a '' character. $ while read -r l; do echo $l; done < input Output should be \ one line with a '\' character. $ sed '/\\$/{N; s/\\\n//;}' input Output should be one line with a '\' character. $ perl -0777 -pe 's/\\\n//s' input Output should be one line with a '\' character.
请注意,perl解决方案只适用于/ g标志,我甚至不知道如何修改sed来处理多个延续,从而展示这些解决方案的脆弱性。 – 2009-08-04 17:51:24