0
我有两个csv文件。 我想将它们串联起来。concatinating .csv文件列明智
我发现这个Merge multiple csv files awk column-wise, no match给出的命令在Windows命令提示符下不起作用。
请帮助。谢谢你让我的生活更轻松。
我有两个csv文件。 我想将它们串联起来。concatinating .csv文件列明智
我发现这个Merge multiple csv files awk column-wise, no match给出的命令在Windows命令提示符下不起作用。
请帮助。谢谢你让我的生活更轻松。
理想情况下,您可以使用unix“粘贴”命令来执行此操作。安装Windows SUA后,您可以使用粘贴。不过,我试了一下,因为它仍然是基于unix的,它不喜欢文件中的CR。即Unix只使用LF,Windows使用CRLF,粘贴会保留CRs,以便最终得到回车中线。
编写一个paste.exe来做这件事真的不需要太多的努力,我敢肯定有人肯定已经做到了 - 但我找不到。
没有单一的命令行回答这个与Windows(不使用AWK的Windows版本或粘贴或者也许sed的...)
所以......这里有一个bat文件来为你做它。它可以处理多个输入文件,最后一个参数是输出文件名。
@echo off
setlocal
if x%3 equ x goto usage
set tmpFile=%tmp%\JoiningTxt-%random%.csv
set tmpFile2=%tmp%\JoiningTxt2-%random%.csv
rem Set up the first file
copy %1 %tmpFile% > NUL
shift
:loop
rem append each file in turn
if x%2 equ x goto complete
call :Append %tmpFile% %1
shift
goto loop
:Append
rem Concatenate the 2 files together. The setlocals are to allow special chars to work !^etc
(
for /f "tokens=*" %%a in (%1) do (
setlocal DISABLEDELAYEDEXPANSION
set "FirstFileLine=%%a"
setlocal ENABLEDELAYEDEXPANSION
set /p SecondFileLine=
echo !FirstFileLine!,!SecondFileLine!>>%tmpFile2%
endlocal
endlocal
)
)<%2
copy %tmpFile2% %1 > NUL
del %tmpFile2%
goto :EOF
:complete
copy %tmpFile% %1 > NUL
del %tmpFile%
goto end
:usage
echo Usage:
echo %0 file1In file2In file...In fileOut
echo You must have at least 2 in files
goto end
:end
endlocal