alexiot
Goto Top

Letzte Zeile einer .txt in eine andere .txt ausschneiden per Batch

Hallo zusammen,

zu meinem obrigen Thema habe ich leider nur in Richtung löschen und nicht in Richtung ausschneiden etwas passendes
gefunden.

Ausgangssituation:
Ich habe eine Textdatei mit Hostnames die in etwa so aufgebaut ist:
XX0258XX001
XX0268XX005
XX0252XX003

Ich möchte nun, dass die letzt Zeile der Hostname.txt in eine andere Textdatei ausgeschnitten wird.
Wie viele Hostnames in der Textdatei sind ist immer unterschiedlich.

Vielen Dank für die bisher immer sehr schnelle Hilfe!

Content-Key: 282298

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

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

Member: TlBERlUS
TlBERlUS Sep 09, 2015 updated at 06:26:47 (UTC)
Goto Top
Guten Morgen,

Powershell:
$path = "Pfad"  

$arr = gc "$path\Hostname.txt"  
$arr[-1] | Out-File $path\output.txt
$arr[-1] = ""  
$arr | out-file $path\Hostname.txt


Grüße,

Tiberius
Member: AlexIOT
AlexIOT Sep 09, 2015 at 11:39:16 (UTC)
Goto Top
Danke für die Antwort,

aber wenn ich die output.txt lösche und das Skript wieder ausführe haut es nicht mehr hin....
Wäre schön wenn du das noch fixen könntest.

Grüße,

Alex
Mitglied: 122990
Solution 122990 Sep 09, 2015 updated at 14:11:31 (UTC)
Goto Top
$pathIN = 'C:\hostname.txt'  
$pathOut = 'C:\ouput.txt'  
$file = gc $pathIN
$file[0..($file.length -2)] | out-file $pathIN
$file[-1] | out-file $pathOut
Gruß grexit
Member: TlBERlUS
TlBERlUS Sep 09, 2015 at 11:51:32 (UTC)
Goto Top
Hast recht, da habe ich nicht zuende gedacht.

$path = "Pfad"  
[System.Collections.ArrayList] $arr =gc $path\Hostname.txt
$arr[-1] | Out-File $path\output.txt
$arr.Remove($arr[-1])
$arr | out-file $path\Hostname.txt