简体   繁体   中英

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). In the Search Mode section of the dialog, check the Extended radio button (interpret \n and such). Then replace all occurrences with nothing (empty string)


  • NOTEPAD++:

In Notepad++, you can do it as:

  1. Select the lines you want to join ( Ctrl + A to select all)
  2. Choose 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.

Using VS Code

在此处输入图像描述

Using 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:

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

The output will be in output.txt and your original file will be unchanged.

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. 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 ). 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.

-- Edit: I see this was tagged with word . You can replace ^p with a space ( ) character and it will do what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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