Link to home
Start Free TrialLog in
Avatar of Ragaz Mahe
Ragaz Mahe

asked on

Deletion of last line in a File & adding a new last line

I am having a file named Trade.txt having n number of lines.
I need the last line to get deleted ( The last line is the string "Report type" ) & I need to add new characters to the last line.
The new character is "Trans Date".

Please help me somebody as I am new to scripting
Avatar of Bill Prew
Bill Prew

Give this a try, adjust the file names near the top...

@echo off
setlocal

set FileIn=in.txt
set FileOut=out.txt

find /v /i "report type" <"%FileIn%" >"%FileOut%"
echo Trans Date>>"%FileOut%"

Open in new window


»bp
@Ragaz

Is the last line the only place the "Report type" string will ever appear in the file?
Avatar of Ragaz Mahe

ASKER

@aikimark, Its like anywhere in the file the string "report type" would be present. But I need the string in the last line alone to be replaced.
@Bill Prew,  Kindly  be noted that, the said string "report type" would be anywhere in the file. But I need the string in the last line alone to be replaced.
That's what my script did.


»bp
@Bill Prew,

I have tested your code, I could see that the last line is getting replaced with Trans date. At the same time, the string(report type) that is present in all the other places other than the last line is getting disappeared in the output file. Please advise
Can you run Powershell or VBscript scripts?
@aikimark, I am sorry, but i need to run through a BAT or PERL Script
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial