johnb6767
asked on
Remove the last character from a line in batch.....
I have a simple text file that I have created in a batch script that is a result of the reg export of [HKEY_CURRENT_USER\printer s\Connecti ons]
Next line trims it down just fine, to the \\server\share format, but leaves the "]" at the end, that I cannot seem to remove..... Been fighting it long enough, now Ill let yall take a stab.. Sure its simple, but this one eludes me for some reason.....
So......
Goal is to get a text file with the following in it......
\\server\5034C]
\\server\5034C_PS]
\\server\PB-2050]
\\server\Xerox Phaser 6300N PS]
\\Computername\RICOH Aficio SP C222DN PCL 6]
To look like..... Just simply remove the last bracket.....
\\server\5034C
\\server\5034C_PS
\\server\PB-2050
\\server\Xerox Phaser 6300N PS
\\Computername\RICOH Aficio SP C222DN PCL 6
Next line trims it down just fine, to the \\server\share format, but leaves the "]" at the end, that I cannot seem to remove..... Been fighting it long enough, now Ill let yall take a stab.. Sure its simple, but this one eludes me for some reason.....
So......
Goal is to get a text file with the following in it......
\\server\5034C]
\\server\5034C_PS]
\\server\PB-2050]
\\server\Xerox Phaser 6300N PS]
\\Computername\RICOH Aficio SP C222DN PCL 6]
To look like..... Just simply remove the last bracket.....
\\server\5034C
\\server\5034C_PS
\\server\PB-2050
\\server\Xerox Phaser 6300N PS
\\Computername\RICOH Aficio SP C222DN PCL 6
Do you have to use a batch file? VBScript or Powershell script would be more flexable.
another way ... download this tool:
http://www.paulslore.com/utils/chgstr.zip
then you can change your text file like this:
chgstr "]" "" myfile.txt
http://www.paulslore.com/utils/chgstr.zip
then you can change your text file like this:
chgstr "]" "" myfile.txt
... add that last line to your batch file and viola!
$File_To_Change = "C:\Full\Path\To\File.txt"
$File = Get-Item -path $File_To_Change
(Get-Content $File.FullName) | % {$_ -replace "]", ""} | Set-Content -path $File.FullName
Save above as xxx.ps1 (powershell script) and call it from your batch file will also work.
batch file command
Powershell &C:\xxx.ps1
Cheers
$File = Get-Item -path $File_To_Change
(Get-Content $File.FullName) | % {$_ -replace "]", ""} | Set-Content -path $File.FullName
Save above as xxx.ps1 (powershell script) and call it from your batch file will also work.
batch file command
Powershell &C:\xxx.ps1
Cheers
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is already a pre existing series of scripts designed to capture and rebuild profiles on reimaged machines, and im just looking for something to add to the existing script..... I know it can be done, just my syntax is whacked......
Like using the :~0, -1 switches......
Like using the :~0, -1 switches......
ASKER
Steve, I dont know why I didnt think of that..... Incredibly simple.... Works great!!!
I love it when you spend too much time overthinking......
Thanks to all for the quick help.....
I love it when you spend too much time overthinking......
Thanks to all for the quick help.....
ASKER
Thanks!!
You guys and your scripting powers are amazing. If any of you think you can solve this riddle, I would be greatly appreciative.
https://www.experts-exchange.com/questions/26568755/Copy-data-via-Windows-scheduler.html
https://www.experts-exchange.com/questions/26568755/Copy-data-via-Windows-scheduler.html
if so edit with vi
then in vi type
:1,$s/]//g