如果前面的最后一个字符是左括号,我想删除换行符。所以这个:
one
two(
three
应该成为:
one
two(three
我用awk和sed尝试了一些事情,但无法做到正确:
awk '/\($/ {printf "%s ", $0} {print; next}'
sed 's/($/(/g'
答案 0 :(得分:2)
使用gnu sed
即可:
sed '/($/{N;s/\n//;}' file
one
two(three
或使用awk
:
awk '/\($/{p=$0; getline; printf "%s", p} 1' file
one
two(three
答案 1 :(得分:2)
使用awk:
正则表达式:var query = data.Select
(
p => new Parent()
{
Id = p.Id,
Name = p.Name,
Children = p.Children.Take(2).ToList()
}
);
替换为:\(\n
(
打印:
awk 'BEGIN {RS=""}{gsub(/\(\n/, "(",$0); print $0}' file_name
^ regex ^ replace
答案 2 :(得分:0)
awk '/^t/{printf $0}NR==1;END{print ""}' file
one
two(three