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