decoded
asked on
Script to edit text files
Hello Experts,
I am newbie when it comes to scrpting, is there a way to edit/erase this first 14 characters of a certain text file.
THanks in advance
I am newbie when it comes to scrpting, is there a way to edit/erase this first 14 characters of a certain text file.
THanks in advance
Batch, Powershell, Kixtart, VBScript?
ASKER
Batch
Is there a specific reason for not using PowerShell as it would certainly be much easier? I have written text replacement utilities for cmd.exe in the past, they compiled utilities though. Functionality to achieve this is baked in to PowerShell.
ASKER
I have very little expereince using powershells. If you give me a breif explanation i would probably get it.
Thanks
Thanks
ASKER
Can yuo assist me with the powershell...it does look it would be alot easier.
Thanks
Thanks
Try this batch file:
BATCHFILE filename.txt
Where 'BATCHFILE' is the name of your batch file and 'filename.txt' is the name of your text file.
@echo off
if "%~1"=="" echo Usage: %0 filename.txt & exit /b
if not exist "%~1" echo Cannot find file & exit /b
set /p line=<"%~f1"
echo.%line:~14%>"%temp%\%~nx1.tmp"
more +1 "%~f1">>"%temp%\%~nx1.tmp"
move "%temp%\%~xn1.tmp" "%~f1""
NOTE: Copy & Paste the code into Notepad and save it as a .BAT file. Run the batch file specifying a filename as a command line parameter like this:BATCHFILE filename.txt
Where 'BATCHFILE' is the name of your batch file and 'filename.txt' is the name of your text file.
Do you want to remove the 14 characters from the file NAME, or from the file CONTENTS?
If CONTENTS, then do you want to remove the first 14 characters from just the first line, or every line?
~bp
If CONTENTS, then do you want to remove the first 14 characters from just the first line, or every line?
~bp
decoded
Please permit me to draw your attention to my earlier comment http:#37782035 - the solution to this question.
Thnk you.
Please permit me to draw your attention to my earlier comment http:#37782035 - the solution to this question.
Thnk you.
ASKER
i used perl to get this done...wrote some lines of code and Mission accomplished
while(<*.dat>) {
open(IN, $_) or die ("Cannot open $_: $!");
my @in = <IN>;
close(IN);
shift @in;
open(OUT, ">new-$_") or die ("Cannot open $_.new: $!");
print OUT @in;
close(OUT);
}
thanks
while(<*.dat>) {
open(IN, $_) or die ("Cannot open $_: $!");
my @in = <IN>;
close(IN);
shift @in;
open(OUT, ">new-$_") or die ("Cannot open $_.new: $!");
print OUT @in;
close(OUT);
}
thanks
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for decoded's comment #37858196
for the following reason:
Most reliable way to do it...doesn't cause orginal file to get damage. With my sloution it creates a new simple file.
Accepted answer: 0 points for decoded's comment #37858196
for the following reason:
Most reliable way to do it...doesn't cause orginal file to get damage. With my sloution it creates a new simple file.
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 soultion works as well...sorry for not taking a further look into you soultion...in no way I was trying to cheat.
Great Job
paultomasi
Great Job
paultomasi