Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 215 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to combine multiple lines in a single text file into one line, in Windows?

#1
I have a multiple standard text files that follow this format, with varying numbers of lines in each file:

Line1
Line2
Line3
Line4

I want to merge every line into one, with a space in between each set of characters, so the text file would look as such:

Line1 Line2 Line3 Line3

...and so on. This needs to work with any given number of lines, due to the fact that each text file contains a different number of lines. My intention is *not* to merge the lines in the text files; I want each text file to remain separate. All the solutions I have found online either don't quite fit this or work exclusively with UNIX. I am running Windows 7. This can be done in Powershell, VBS, Batch, a particular program, doesn't matter, it just needs to work with Windows.

Much appreciated!
Reply

#2
Using PowerShell give this a try and see if it's what you want:

$my_file = "C:\file.txt"
$out_file = "C:\out.txt"
(Get-Content -Path $my_file) -join " " | Set-Content -Path $out_file
Reply

#3
@ECHO OFF
setlocal
(SET var=)
FOR /f "delims=" %%x IN (list.txt) DO (
CALL SET var=%%var%% %%x
)
SET var=%var:~1%
echo var=%var%=

Where list.txt is the file containing your lines and var is the variable into which you want the lines concatenated.
Reply

#4
Something like this?

(gc C:\test.txt) -join " "

Reply

#5
Using batch:

for /f "usebackqdelims=" %%i in ("infile.txt") do @<nul set /p"=%%i ">>"outfile.txt"
>>"outfile.txt" echo.
Reply

#6
For the sake of completeness here's another solution in [tag:vbscript]:

Set fso = CreateObject("Scripting.FileSystemObject")

Set infile = fso.OpenTextFile("C:\infile.txt")
Set outfile = fso.OpenTextFile("C:\outfile.txt", 2, True)

If Not infile.AtEndOfStream Then outfile.Write infile.ReadLine
Do Until infile.AtEndOfStream
outfile.Write " " & infile.ReadLine
Loop

infile.Close
outfile.Close
Reply

#7
Install git-scm, cygwin or something else that contains bash, then you can do

cat *.txt | tr "\n" " "
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through