Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用perl追加行_Perl - Fatal编程技术网

用perl追加行

用perl追加行,perl,Perl,我的输入行: Movies: Action Adventure Biography Comedy Books: Biography Romance Sci-Fi War 我的问题(用Perl实现):检查一行是什么样子的,如果它以“:”结尾,请在它后面追加下一行 在我的例子中,它将包含“书籍”的行与包含“传记”的行连接起来,但这只是一个例子——行的内容可能在许多方面有所不同 Movies: Action Adventure Biography Comedy Books: Biography Ro

我的输入行:

Movies: Action
Adventure
Biography
Comedy
Books:
Biography
Romance
Sci-Fi
War
我的问题(用Perl实现):检查一行是什么样子的,如果它以“:”结尾,请在它后面追加下一行

在我的例子中,它将包含“书籍”的行与包含“传记”的行连接起来,但这只是一个例子——行的内容可能在许多方面有所不同

Movies: Action
Adventure
Biography
Comedy
Books: Biography
Romance
Sci-Fi
War
你可以做:

perl -pe 's/\r?\n$/ / if(/:\s*$/)' file

如果您同意在
之后没有空格:

可以执行以下操作:

perl -pe 's/\r?\n$/ / if(/:\s*$/)' file


如果您同意在
之后没有空格:

这里有一个小程序来处理您的输入:

while (<>) {
  s/\s+$/ / if /:$/;
  print;
}

这里有一个处理您输入的小程序:

while (<>) {
  s/\s+$/ / if /:$/;
  print;
}

类似于
$text=~s/:\s*\n/:/msg

类似于
$text=~s/:\s*\n/:/msg

可以使用查找后断言:

s/(?<=:)\s*\n/ /gs;

s/(?可以使用查找后断言:

s/(?<=:)\s*\n/ /gs;

s/(?:谢谢。我也不知道。:-)-1表示多余使用s标志。:谢谢。我也不知道。:--1表示多余使用s标志。