Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Script to edit text files

Posted on 2012-03-28
15
Medium Priority
?
530 Views
Last Modified: 2012-04-18
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
0
Comment
Question by:decoded
15 Comments
 
LVL 3

Expert Comment

by:KruglerD
ID: 37779552
Batch, Powershell, Kixtart, VBScript?
0
 

Author Comment

by:decoded
ID: 37779559
Batch
0
 
LVL 8

Expert Comment

by:Brent Challis
ID: 37780119
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:decoded
ID: 37781756
I have very little expereince using powershells. If you give me a breif explanation i would probably get it.

Thanks
0
 

Author Comment

by:decoded
ID: 37782035
Can yuo assist me with the powershell...it does look it would be alot easier.

Thanks
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 37788226
Try this batch 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""

Open in new window

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.
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 37791976
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
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 37800187
decoded

Please permit me to draw your attention to my earlier comment http:#37782035 - the solution to this question.

Thnk you.
0
 

Author Comment

by:decoded
ID: 37858196
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
0
 

Author Comment

by:decoded
ID: 37858656
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.
0
 
LVL 11

Accepted Solution

by:
paultomasi earned 2000 total points
ID: 37858657
Something strange going on here...

decoded

In my comment (http:#37800187) above where I wrote:    
Please permit me to draw your attention to my earlier comment http:#37782035
Did a comment ID37782035 get deleted or something, or did I missquote the comment ID number?

Did my solution in http:#37788226 (above) not work then?

Incidentally, you didn't say anything about not overwriting the original file. You actually stated:
...is there a way to edit/erase this first 14 characters...
Using the relevent lines of code from my comment above, and omiting the last line (Line 8), you would end up with a new file named 'new-filename' (whatever your filename is). Please see the code below:
@echo off
if "%~1"=="" echo Usage: %0 filename & exit /b
if not exist "%~1" echo Cannot find the file %~1 & exit /b
set /p line=<"%~f1"
echo.%line:~14%>"new-%~nx1"
more +1 "%~f1">>"new-%~nx1"

Open in new window

I also feel this question, and solution has value. It's not something that crops up frequently enough to justify discarding.

I feel a little bit cheated as decoded has moved the goalposts without prior notice, and after a working solution to the question had already been submitted.
0
 

Author Closing Comment

by:decoded
ID: 37861707
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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Simple Linear Regression
Suggested Courses
Course of the Month12 days, 7 hours left to enroll

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question