'How to make multiple line text into a single line and add some commas

i want to make a multiple line txt file (reading it on notepad++) into a single line texte with some commas. Example with the text

123
123
123
123

to:

123,123,123,123

Is it possible to do it with notepad++? if not, how can i do it?



Solution 1:[1]

You can do it in notepad++, I will write my solution in python programming language.

# You open the file
file = open("Location of the file right click on the text file and copy relative file.")
# You read the whole file and put it in a list where each line would be one 
# item in the list.
readFile = file.read().split("\n")
# Set a new variable so you can concatinate a string
text = ""
# Loop through the list of rows
for i in range(0, len(readFile), 1):
      # Concatinate the each row into one string and add a comma and a space.
     text = text + readFile[i] + ", "
# Print the text
print(text)

That is one way you can do this.

Solution 2:[2]

  • Find what: \R
  • Replace with: ,

Where \R stands for any kind of linebreak (i.e. \r, \n, \r\n)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Makisa9999
Solution 2 Toto