otto54
Goto Top

Suchen von ".-pins" und Ersetzen mit "-pins"

Ein freundliches Hallo hier ans Forum.

Beim Export einer Tabelle im tsv Format kommt es bei mir zu einer Fehlwirkung. Dies korrigiere ich bisher mit Notepad++.

Ich möchte nun mit Windows10 Bordmitteln
  • diese Textdatei.tsv (UTF-8, 11.000 Zeilen mit Tab als Trennzeichen) in ein Zieldatei.csv kopieren (UTF8, 11.000 Zeilen mit Tab als Trennzeichen)
  • und darin Text ".&pins" austauschen gegen "&pins". Der Punkt ist zuviel. Kommt bei 11.174 Zeilen 1.461 mal vor. Ursache nicht gefunden.
  • Danach die Zieldatei.csv packen in eine Zieldatei.zip.

Batch und Dateien liegen im gleichen Ordner.

Grund: Dann könnte ein Batch-Job die Arbeit komplett erledigen.


Hier ist die Textdatei.tsv in einem Archiv.zip 1,9 MB

 
      set "quelle=HistoricPlace - HP-GRSL.tsv"   
      set "ziel=HP-GRSL.csv"   
      set "Suchen=.&pins"  
      set "Ersetzen=&pins"  
      
      Echo Am Anfang über 1.400 Fundstellen
      find /c /i  ".&pins" "%quelle%"  
       
      :Process
      Suchen und Ersetzen 
      
      
      Echo Am Ende 0 Fundstellen
      find /c /i  ".&pins" "%ziel%"  
      pause 
      
      packen/zippen %ziel% HP-GRSL.zip

Wie löse ich dies am besten?

Danke für Dein Interesse.

Content-Key: 601553

Url: https://administrator.de/contentid/601553

Printed on: May 26, 2024 at 03:05 o'clock

Member: NordicMike
NordicMike Sep 03, 2020 at 07:28:32 (UTC)
Goto Top
Mit sowas:

https://www.tutorialspoint.com/batch_script/batch_script_replace_string. ...

Aber du musst die Datei vorher einlesen, um sie als Variable zu haben.
Member: SlainteMhath
SlainteMhath Sep 03, 2020 updated at 07:50:16 (UTC)
Goto Top
Moin,

würde ich mit Powershell machen. Wurde sicher schon 20mal im Forum behandelt und gelöst. Verwende mal die Suchfunktion

lg,
Slainte

/EDIT: Alternativ 15sec Google Suche:
((Get-Content -path C:\ReplaceDemo.txt -Raw) -replace 'brown','white') | Set-Content -Path C:\ReplaceDemo.txt  
Member: Otto54
Otto54 Sep 03, 2020 at 07:49:33 (UTC)
Goto Top
Danke für die schnelle Antwort. Ich bin kein Programmierer.
Ich scheitere bereits im Einstieg.

1)
Kann ich die Datei als Ganzes öffnen, durchsuchen, alle Treffer austauschen?

wenn Nein
2)
Wie lese ich die Datei.tsv zeilenweise ein?

set str=%str:.&pins=&pins%
Suchen und ersetzen könnte so wirken. Hoffentlich stört nicht der Punkt vor dem Sonderzeichen &. Beides ist zwingend.
Wie schreibe ich die bearbeitete Zeile in die Datei.csv?

Danke
Member: SlainteMhath
SlainteMhath Sep 03, 2020 at 07:50:55 (UTC)
Goto Top
siehe oben
Member: NordicMike
NordicMike Sep 03, 2020 updated at 10:56:16 (UTC)
Goto Top
Am Anfang hat man viele Fragen. Das kostet aber auch viel Zeit sie alle zu stellen und auf Antwort zu warten. Schneller gehts mit der Suche, da habe ich sowas gefunden:

Batch: Textdatei Zeilenweise auslesen
Member: Dr.Bit
Dr.Bit Sep 03, 2020 at 08:30:59 (UTC)
Goto Top
Zitat von @Otto54:

Danke für die schnelle Antwort. Ich bin kein Programmierer.
Ich scheitere bereits im Einstieg.


Ich kann Dich soooooooooooooo gut verstehen.face-smile

🖖
Mitglied: 145916
Solution 145916 Sep 03, 2020 updated at 12:09:11 (UTC)
Goto Top
CSV mit Batch.. aua ("Hände über dem Kopf zusammenschlag") face-big-smile
Da fällt mir nur noch Otto ein ...
@echo off
set "file=D:\daten.csv"  
set "zipfile=D:\daten.zip"  
powershell -EP Bypass -C "(gc '%file%' -Raw) -replace '\.&pins','&pins' | sc '%file%';Compress-Archive -Path '%file%' -DestinationPath '%zipfile%'"  
Member: Otto54
Otto54 Sep 03, 2020 at 10:52:07 (UTC)
Goto Top
Zitat von @145916:

CSV mit Batch.. aua ("Hände über dem Kopf zusammenschlag") face-big-smile

csv mit Batch reparieren. Ich stamme noch aus dem DOS-Zeitalter.
Powershell ist mir fremd.

eaglefinder, herzlichen Dank. Funktioniert wunderbar. Laufzeit 6 Sekunden, siehe Bildschirmkopie.


@echo off
echo Zeit Anfang: %TIME%

set "quelle=HistoricPlace - HP-GRSL.tsv"   
set "file=HP-GRSL.csv"  
set "zipfile=HP-GRSL.zip"  

copy "C:\Users\Riehl\Downloads\HistoricPlace - HP-GRSL.tsv" "%quelle%"  
copy "C:\Users\Riehl\Downloads\HistoricPlace - HP-GRSL.tsv" "%file%"  

echo Anzahl Treffer in tsv.
find /c /i  ".&pins" "%quelle%"  

if exist "%zipfile%" del "%zipfile%"  

powershell -EP Bypass -C "(gc '%file%') -replace '.&pins','&pins' | sc '%file%';Compress-Archive -Path '%file%' -DestinationPath '%zipfile%'"  

echo.
echo Austausch ist erfolgt. Anzahl Treffer in csv.
find /c /i  ".&pins" "%file%"  

echo Zeit Ende: %TIME%
pause

rem [content:601553#1476605]
03-09-_2020_12-43-58