仅在引号括起时删除换行符

时间:2022-09-15 15:43:54

I have a large amount of data in a text file that has been giving me some issues. A lot of the records in the file have line breaks in between the record. For example this is what my data looks like currently:

我在文本文件中有大量数据,这些数据一直给我一些问题。文件中的许多记录在记录之间都有换行符。例如,这是我目前的数据:

30670169,           Corvette,   EL-P078675,     EL-P078675, Chevrolet  Corvette C6 Color Matching Millenium Yellow License Plate Frame,     "Made from high-quality billet aluminum, this stylish license frame is custom painted to precisely match the color of your C6 Corvette.

It features an engraved OEM style nameplate. High-gloss finished will never rust.

12"" x 6"" in standard size. Includes color matched screw covers and hardware.

This is a special custom made item. It takes 10-15 business days to ship.

Brand new official licensed product."

This is how is should read:

这是应该如何阅读:

30670169,           Corvette,   EL-P078675,     EL-P078675, Chevrolet  Corvette C6 Color Matching Millenium Yellow License Plate Frame,     "Made from high-quality billet aluminum, this stylish license frame is custom painted to precisely match the color of your C6 Corvette. It features an engraved OEM style nameplate. High-gloss finished will never rust. 12"" x 6"" in standard size. Includes color matched screw covers and hardware. This is a special custom made item. It takes 10-15 business days to ship. Brand new official licensed product."

I need a method to delete line breaks ONLY if they are surrounded by quotes. Anyone have any ideas?

我需要一种方法来删除换行符,如果它们被引号括起来的话。有人有主意吗?

2 个解决方案

#1


1  

Try using the Find/Replace function of Notepad++.

尝试使用Notepad ++的查找/替换功能。

Find:

\r(?!\n)

Replace with: (space)

替换为:(空格)

You will need to check the regular expression checkbox:

您需要检查正则表达式复选框:

仅在引号括起时删除换行符

Try replacing in a few lines first (select the first 80 lines for example) and then replace in selection just to see. If that works, you can proceed with the whole file.

首先尝试替换几行(例如,选择前80行),然后在选择中替换以查看。如果可以,您可以继续处理整个文件。

In the above \r will match a CR and \n will match an LF. (?!\n) is a special group that means 'don't match \r if it is followed by \n'.

在上面\ r \ n将匹配CR和\ n将匹配LF。 (?!\ n)是一个特殊的组,意思是'如果后跟\ n'则不匹配\ r'。

Note: I think that notepad++ sometimes doesn't do the replace correctly, so if replacing the whole file at once cause issues, try replacing in smaller batches.

注意:我认为notepad ++有时不能正确替换,因此如果立即更换整个文件会导致问题,请尝试更换较小的批次。

I usually use a script to do something like this but I don't think you'd be ready to use a script if you're not used to it :s

我通常使用脚本来做这样的事情,但如果你不习惯,我认为你不准备使用脚本:s

#2


1  

You can open the csv file in excel and remove line breaks as shown in this link: http://www.excelblog.ca/remove-line-breaks-from-excel-cell/

您可以在Excel中打开csv文件并删除换行符,如以下链接所示:http://www.excelblog.ca/remove-line-breaks-from-excel-cell/

仅在引号括起时删除换行符

仅在引号括起时删除换行符

You can do it on one specific column as well.

您也可以在一个特定列上执行此操作。

#1


1  

Try using the Find/Replace function of Notepad++.

尝试使用Notepad ++的查找/替换功能。

Find:

\r(?!\n)

Replace with: (space)

替换为:(空格)

You will need to check the regular expression checkbox:

您需要检查正则表达式复选框:

仅在引号括起时删除换行符

Try replacing in a few lines first (select the first 80 lines for example) and then replace in selection just to see. If that works, you can proceed with the whole file.

首先尝试替换几行(例如,选择前80行),然后在选择中替换以查看。如果可以,您可以继续处理整个文件。

In the above \r will match a CR and \n will match an LF. (?!\n) is a special group that means 'don't match \r if it is followed by \n'.

在上面\ r \ n将匹配CR和\ n将匹配LF。 (?!\ n)是一个特殊的组,意思是'如果后跟\ n'则不匹配\ r'。

Note: I think that notepad++ sometimes doesn't do the replace correctly, so if replacing the whole file at once cause issues, try replacing in smaller batches.

注意:我认为notepad ++有时不能正确替换,因此如果立即更换整个文件会导致问题,请尝试更换较小的批次。

I usually use a script to do something like this but I don't think you'd be ready to use a script if you're not used to it :s

我通常使用脚本来做这样的事情,但如果你不习惯,我认为你不准备使用脚本:s

#2


1  

You can open the csv file in excel and remove line breaks as shown in this link: http://www.excelblog.ca/remove-line-breaks-from-excel-cell/

您可以在Excel中打开csv文件并删除换行符,如以下链接所示:http://www.excelblog.ca/remove-line-breaks-from-excel-cell/

仅在引号括起时删除换行符

仅在引号括起时删除换行符

You can do it on one specific column as well.

您也可以在一个特定列上执行此操作。