jweghorn
Goto Top

Batchdatei - HTML-Code aus CSV-Datei entfernen

Hallo zusammen,

ich habe eine CSV-Datei, in der sich in einer bestimmten Spalte, Aufzählungspunkte mit Text befinden. Diese sind
als HTML-Code vercoded.

In Excel kann ich das jetzt prinzipiell leicht bearbeiten.
Man markiert die entsprechende Spalte, geht auf "Suchen und Ersetzen", gibt "<*>" ein und
schon sind alle Codes draußen.

Das Problem ist, dass diese CSV-Datei aus einem ERP-System erzeugt wird und ich
mittels Batch-Datei automatisiert diese CSV-Datei bearbeiten muss und dadurch die
HTML-Codes entfernt werden müssen.

Kann mir einer sagen, wie ich diesen Code aufbaue?

Schon jetzt vielen Dank für Eure Hilfe. Ich bin für jeden Hinweis dankbar.

Gruss
Jörg

Content-Key: 358092

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

Printed on: April 19, 2024 at 23:04 o'clock

Mitglied: 134998
Solution 134998 Dec 13, 2017, updated at Dec 14, 2017 at 09:26:11 (UTC)
Goto Top
Hi,
can be done with a single line of code
powershell -ExecutionPolicy ByPass -Command "(Import-csv 'C:\file.csv' -Delimiter ';') | %%{$_.'ColumnName' = $_.'ColumnName' -replace '^.*|<[^>]+>|[\r\n]+','';$_} | export-csv 'C:\file.csv' -Delimiter ';' -NoType -Encoding UTF8"  
Filenames, CSV-Delimiter and ColumnName where the HTML string is stored need to be adjusted.

Regards
Tom
Member: jweghorn
jweghorn Dec 14, 2017 updated at 07:28:11 (UTC)
Goto Top
Dear Tom,

first - thank you for your help.

I tested it, but it doesn't work. Maybe I did something wrong.
Could you help me again?

Please see the message which I got back.

//Fehlende schließende ")" im Ausdruck.
Bei Zeile:1 Zeichen:91

+ (Import-csv C:\Users\xxxxxxxxx\Desktop\filename.csv -Delimiter <<<< ;) | \Users\xxxxxxxxx\Desktop\filename.csv -Delimiter ';' -NoType -Encoding UTF8
+ CategoryInfo : ParserError: (CloseParenToken:TokenId) , Paren
tContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndParenthesisInExpression


Thank you in advance for your help.

Best regards,
Jörg
Mitglied: 134998
134998 Dec 14, 2017 updated at 07:57:19 (UTC)
Goto Top
Sorry, small typo, is corrected above.

For your information, this line has to be used inside a Batchfile, because percent signs are doubled, otherwise you have to replace the double percent signs with a single one..
Member: jweghorn
jweghorn Dec 14, 2017 at 08:09:29 (UTC)
Goto Top
Dear Tom,

wow - that works. You are great - thank you.

The result is "nearly" perfect, but:
could you extend your command to delete after removing the html codes also the first line into that cells and also delete all line breaks into that cells?

Again thank you in advance for that final question.

Best regards,
Jörg
Mitglied: 134998
134998 Dec 14, 2017 at 09:13:41 (UTC)
Goto Top
Done.
Member: jweghorn
jweghorn Dec 14, 2017 at 09:24:06 (UTC)
Goto Top
Dear Tom,

I got following error message:

Fehlende schließende ")" im Ausdruck.
Bei Zeile:1 Zeichen:182

+ (Import-csv C:\Users\XXXXXX\Desktop\filename.csv -Delimiter ';') | %{$_.ItemTechnicalFeatures = ($_.ItemTechnicalFeatures -replace '<[^>]+>|[\r\n]+','' <<<< ;$_} | export-csv C:\Users\XXXXXX\Desktop\filename.csv -Delimiter ';' -NoType -Encoding UTF8
+ CategoryInfo : ParserError: (CloseParenToken:TokenId) , Paren
tContainsErrorRecordException

+ FullyQualifiedErrorId : MissingEndParenthesisInExpression

Do you have an idea where the problem is?

Again thank you ...

Rgds,
Jörg
Mitglied: 134998
134998 Dec 14, 2017 updated at 09:28:02 (UTC)
Goto Top
Damn, my fingers are way too cold today face-smile. Typo is corrected, sorry again.
Member: jweghorn
jweghorn Dec 14, 2017 at 09:32:14 (UTC)
Goto Top
Dear Tom,

please don't say sorry. It is so great that you help me. It works phantastic. Thank you very very much.
That was great and perfect.

Best regards,
Jörg
Mitglied: 134998
134998 Dec 14, 2017 at 09:33:33 (UTC)
Goto Top
Glad it helped you face-smile.

Have a nice day.
Tom
Member: jweghorn
jweghorn Nov 23, 2018 at 11:24:52 (UTC)
Goto Top