herb58
Goto Top

Windows Batchverarbeitung

Hallo und guten Morgen, ich habe ein Problem mit der Bearbeitung einer CSV Datei mit Windows Batchmitteln:
ich möchte eine Datei einlesen, das Tagesdatum aus dem Dateinamen ermitteln und dieses datum an der ersten Stelle
der Datei wieder einfügen.
Bsp.
Dateiname: Fast_20200602_1034.csv
Trennzeichen: ,
Dateiinhalt:
Timestamp,Conv1 Speed,Conv2 Speed,Conv3 Speed,Conv4 Speed,Conv5 Speed,Conv6 Speed,Conv7 Speed,Conv8 Speed,Conv9 Speed,Conv10 Speed,Conv11 Speed,Conv12 Speed,Conv13 Speed,Conv14 Speed,Conv15 Speed,Conv16 Speed,Conv17 Speed,ID ml 0,ID ml 1,ID ml 2,ID ml 3,ID ml 4,ID ml 5,ID ml 6,ID ml 7,ID ml 8,ID ml 9,ID ml 10,ID ml 11,ID ml 12,ID ml 13,ID ml 14,ID ml 15,ID ml 16,ID ml 17,ID ml 18,ID ml 19,ID ml 20,ID ml 21,ID ml 22,ID ml 23,ID ml 24,ID ml 25,ID ml 26,ID ml 27,ID ml 28,ID ml 29,ID ml 30,ID ml 31,ID ml 32,ID ml 33,ID ml 34,ID ml 35,ID ml 36,ID ml 37,ID ml 38,ID ml 39,ID ml 40,ID ml 41,ID ml 42,ID ml 43,ID ml 44,ID ml 45,ID ml 46,ID ml 47,ID ml 48,ID ml 49,ID ml 50,ID ml 51,ID ml 52,ID ml 53,ID ml 54,ID ml 55,ID ml 56,ID ml 57,ID ml 58,ID ml 59,ID ml 60,ID ml 61,ID ml 62,ID ml 63,ID ml 64,ID ml 65,ID ml 66,ID ml 67,ID ml 68,ID ml 69,ID ml 70,ID ml 71,ID ml 72,ID ml 73,ID ml 74,ID ml 75,ID ml 76,ID ml 77,ID ml 78,ID ml 79,ID ml 80,ID ml 81
10:34:45.032,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0,0,0,0,0,994,0,0,0,0,0,0,0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,0,0,0,0,0

Das Ergebniß soll so aussehen:
Timestamp,Conv1 Speed,Conv2 Speed,Conv3 Speed,Conv4 Speed,Conv5 Speed,Conv6 Speed,Conv7 Speed,Conv8 Speed,Conv9 Speed,Conv10 Speed,Conv11 Speed,Conv12 Speed,Conv13 Speed,Conv14 Speed,Conv15 Speed,Conv16 Speed,Conv17 Speed,ID ml 0,ID ml 1,ID ml 2,ID ml 3,ID ml 4,ID ml 5,ID ml 6,ID ml 7,ID ml 8,ID ml 9,ID ml 10,ID ml 11,ID ml 12,ID ml 13,ID ml 14,ID ml 15,ID ml 16,ID ml 17,ID ml 18,ID ml 19,ID ml 20,ID ml 21,ID ml 22,ID ml 23,ID ml 24,ID ml 25,ID ml 26,ID ml 27,ID ml 28,ID ml 29,ID ml 30,ID ml 31,ID ml 32,ID ml 33,ID ml 34,ID ml 35,ID ml 36,ID ml 37,ID ml 38,ID ml 39,ID ml 40,ID ml 41,ID ml 42,ID ml 43,ID ml 44,ID ml 45,ID ml 46,ID ml 47,ID ml 48,ID ml 49,ID ml 50,ID ml 51,ID ml 52,ID ml 53,ID ml 54,ID ml 55,ID ml 56,ID ml 57,ID ml 58,ID ml 59,ID ml 60,ID ml 61,ID ml 62,ID ml 63,ID ml 64,ID ml 65,ID ml 66,ID ml 67,ID ml 68,ID ml 69,ID ml 70,ID ml 71,ID ml 72,ID ml 73,ID ml 74,ID ml 75,ID ml 76,ID ml 77,ID ml 78,ID ml 79,ID ml 80,ID ml 81
2020060210:34:45.032,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0,0,0,0,0,994,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,993,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
2020060210:34:45.504,0.0,0.0,0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.0,0.0,0,0,0,0,0,994,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,993,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
2020060210:34:55.622,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0,0,0,0,0,994,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,993,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
2020060210:34:57.857,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0,0,0,0,0,994,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,993,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
2020060210:34:59.481,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0,0,0,0,0,994,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,993,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

Also das Tagesdatum aus dem Dateinamen in jeder Zeile hinzufügen.

Kann mir vllt jemand einen Tip geben, wie ich das mit einer CMD durchführen kann??
Ich wäre für eine Antwort sehr dankbar
Viele Grüße und Danke Herbert Heppner

Content-ID: 625234

Url: https://administrator.de/forum/windows-batchverarbeitung-625234.html

Ausgedruckt am: 07.04.2025 um 20:04 Uhr

TK1987
TK1987 24.11.2020 aktualisiert um 12:31:58 Uhr
Goto Top
Moin,

mit Batch:
@echo off
set quelle=Fast_20200602_1034.csv
set ziel=neu.csv

for /f "UseBackq delims=" %%a in ("%quelle%") do (  
  echo %%a > "%ziel%"  
  goto :next
  )
:next
for /f "UseBackq skip=1 delims=" %%a in ("%quelle%") do echo %quelle:~5,8% %%a >> "%ziel%"  

deutlich sauberer wird es mit Powershell:
$Quelle = "Fast_20200602_1034.csv"  
$Ziel   = "neu.csv"  

$Import = Import-Csv $Quelle -delimiter ','  
Foreach ($Zeile in $Import) { $Zeile.Timestamp = $Quelle.Substring(5,8) + ' ' + $Zeile.Timestamp }  
$Import | Export-Csv -delimiter ',' -NoTypeInformation $Ziel  

Gruß Thomas
herb58
herb58 24.11.2020 um 12:28:09 Uhr
Goto Top
Perfekt face-smile Vielen Dank
und Grüße
Herbert