简体   繁体   English

使用文本编辑器将多行转换为单行

[英]Convert multiple lines to single line using text editor

I have the following words each in a line in a text editor我在文本编辑器的一行中有以下单词

 'about', 
 'above',
 'across',
 'after',
 'afterwards',
 'again',
 'against',
 'all',
 'almost',
 'alone',

Can some help me to convert the above content into a single line using a text editor有人能帮我用文本编辑器把上面的内容转换成一行吗

'about', 'above', 'across', 'after', 'afterwards', 'again', 'against', 'all', 'almost', 'alone',
  • Using Any Advanced Text Editor:使用任何高级文本编辑器:

You could do it in some modern text editors that allow regex find and Replace.您可以在一些允许正则表达式查找和替换的现代文本编辑器中执行此操作。 In such editors, you can do it using - Click on the Replace button and put \r\n or \n , depending on the kind of line ending (CRLF or LF).在此类编辑器中,您可以使用 - 单击“替换”按钮并放置\r\n\n ,具体取决于行尾的类型(CRLF 或 LF)。 In the Search Mode section of the dialog, check the Extended radio button (interpret \n and such).在对话框的搜索模式部分,选中扩展单选按钮(解释\n等)。 Then replace all occurrences with nothing (empty string)然后将所有出现的内容替换为空(空字符串)


  • NOTEPAD++:记事本++:

In Notepad++, you can do it as:在 Notepad++ 中,你可以这样做:

  1. Select the lines you want to join ( Ctrl + A to select all) Select 你要加入的线路( Ctrl + A到 select 全部)
  2. Choose Edit -> Line Operations -> Join Lines选择Edit -> Line Operations -> Join Lines

  • ONLINE TOOLS:在线工具:

I have also found an online tool where you could just paste the text and it would remove all the line breaks.我还找到了一个在线工具,您只需粘贴文本即可删除所有换行符。 Check to see if this tool helps -> https://www.textfixer.com/tools/remove-line-breaks.php or https://codebeautify.org/remove-line-breaks .You could find many such tools online where you could just paste your text and it will remove all the line breaks for you.检查此工具是否有帮助 -> https://www.textfixer.com/tools/remove-line-breaks.phphttps://codebeautify.org/remove-line-breaks 。您可以在线找到许多此类工具您可以在其中粘贴文本,它会为您删除所有换行符。

Using VS Code使用 VS 代码

在此处输入图像描述

Using awk使用 awk

Assuming your text is in a file called break.txt , and the code below is in a file called `break.awk, then the follwing command will work:假设您的文本位于名为break.txt的文件中,而下面的代码位于名为 `break.awk 的文件中,那么以下命令将起作用:

awk -f break.awk break.txt > edited.txt

The output will be in output.txt and your original file will be unchanged. output 将在output.txt中,您的原始文件将保持不变。

BEGIN {
  line = ""
}

{
  line = line " " $1
}

END {
  print line
}

You can do this in any of the more advanced text editors that support regular expressions or some form of control characters by simply replacing \n with a space.您可以在任何支持正则表达式或某种形式的控制字符的更高级的文本编辑器中执行此操作,只需将\n替换为空格即可。 It would help to know which text editor you are using, but generally any of them should use the same, or very similar, syntax (YMMV: depending on the OS, some use \n , others use \r\n ).知道您使用的是哪个文本编辑器会有所帮助,但通常它们中的任何一个都应该使用相同或非常相似的语法(YMMV:取决于操作系统,一些使用\n ,其他使用\r\n )。 To take care of any OS differences, you can use the Regular Expression to match EOL: (\r\n|\n|\r) and replace instances with a space.要处理任何操作系统差异,您可以使用正则表达式匹配 EOL: (\r\n|\n|\r)并将实例替换为空格。

-- Edit: I see this was tagged with word . -- 编辑:我看到这是用word标记的。 You can replace ^p with a space (您可以将^p替换为空格 ( ) character and it will do what you want. ) 字符,它会做你想做的事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM