我有一个平面文件,其线条看起来像
KEYWORD|DATA STRING HERE|32|50135|ANOTHER DATA STRING
KEYWORD|STRING OF DATA|1333|552555666|ANOTHER STRING
KEYWORD|STRING OF MORE DATA|4522452|5345245245|REALLY REALLY REALLY REALLY
LONGSTRING THAT INSERTED A LINE BREAK WHEN I WAS EXTRACTING FROM SQLPLUS/ORACLE
KEYWORD|.....
我该如何删除换行符,以便
KEYWORD|STRING OF MORE DATA|4522452|5345245245|REALLY REALLY REALLY REALLY
LONGSTRING THAT INSERTED A LINE BREAK WHEN I WAS EXTRACTING FROM SQLPLUS/ORACLE
变成
KEYWORD|STRING OF MORE DATA|4522452|5345245245|REALLY REALLY REALLY REALLY LONGSTRING THAT INSERTED A LINE BREAK WHEN I WAS EXTRACTING FROM SQLPLUS/ORACLE
这是在HP-UNIX环境中,我可以将文件移至另一个系统(装有powershell和ruby的Windows框)。
最佳答案
我不知道您使用的是什么工具,但是您可以使用此正则表达式来匹配每个没有\n
的\r
(或者也许是KEYWORD
),因此您可以将其替换为SPACE
,这样就可以了。
DEMO
正则表达式:\r(?!KEYWORD)
(带有全局修饰符)