|
Answer» Hi All
I am looking for help on how to remove the first 3 lines from a text file and save it
my file looks like this.
Changed database context to 'xyz'. ------------------------------------------------------------------------------------------------------- 'cpsdyn', 'rgsconfig', 'rgsdyn', 'rtc', 'rtcab', 'rtcab1', 'rtcdyn', )
I want to remove the first three lines and replace ,) with ). i am trying to write a query on the fly using DOS
i 1. You want to do this?
remove Changed database context to 'xyz'. remove remove ------------------------------------------------------------------------------------------------------- 'cpsdyn', 'rgsconfig', 'rgsdyn', 'rtc', 'rtcab', 'rtcab1', 'rtcdyn', )
2. You say you want to replace ,) with ) but ,) does not appear in your example. Hey Solomon
You are correct. I just want to remove first three lines..
i THINK i figured it out
for /F "tokens=* skip=3 delims=," %%i in (QUERYOUTPUT.TXT) DO ECHO %%i >> QUERYOUTPUT1.TXT
2. YES i want to remove , )
and replace it with )
thanksn HelenHi Salmon,
Or let me put it this way, how can i move to the end of the text file and remove "," and replace it with ")"
Hope this makes sense
thx HelenSo is your requirement 1. Remove first 3 lines? 2. Remove final comma of penultimate line?
as here:
remove Changed database context to 'xyz'. remove remove ------------------------------------------------------------------------------------------------------- 'cpsdyn', 'rgsconfig', 'rgsdyn', 'rtc', 'rtcab', 'rtcab1', 'rtcdyn', <-------------remove this comma ) <---- Question: Is this the last line of the file? ---->
thanks Salmon,
Let me correct it
Changed database context to 'xyz'. ------------------------------------------------------------------------------------------------------- 'cpsdyn', 'rgsconfig', 'rgsdyn', 'rtc', 'rtcab', 'rtcab1', 'rtcdyn', )
is my text file 1. I added ) to the end of my text file to CLOSE the query so it appeared like that. Just ignore ). Assume the last LETTER is a , which i want to remove
it should look like this 'cpsdyn', 'rgsconfig', 'rgsdyn', 'rtc', 'rtcab', 'rtcab1', 'rtcdyn')
Final out put should be
'cpsdyn', 'rgsconfig', 'rgsdyn', 'rtc', 'rtcab', 'rtcab1', 'rtcdyn')
Quote Assume the last letter is a , which i want to remove Where is it? It is not shown.
Hi Please take a fresh look
I am looking for help on how to remove the first 3 lines from a text file and save it
my file looks like this.
Changed database context to 'xyz'. ------------------------------------------------------------------------------------------------------- 'cpsdyn', 'rgsconfig', 'rgsdyn', 'rtc', 'rtcab', 'rtcab1', 'rtcdyn',
what i want is
1. Remove the first three lines --> now i have the solution 2. Replace the last charecter in the file "," with ")". --> i want a solution for this
Finally it should look like
'cpsdyn', 'rgsconfig', 'rgsdyn', 'rtc', 'rtcab', 'rtcab1', 'rtcdyn')
thx
OK Understood Please await suggestion
@echo off setlocal enabledelayedexpansion set lines=0 if exist "output.txt" del "output.txt" for /f "skip=3 delims=" %%A in ( ' type "input.txt" ' ) do set /a lines+=1 set LastLine=%lines% set LineNumber=0 for /f "skip=3 delims=" %%A in ( ' type "input.txt" ' ) do ( set /a LineNumber+=1 set InputLine=%%A if !LineNumber! lss %LastLine% ( echo !InputLine! >> "output.txt" ) else ( echo !InputLine:,=!^) >> "output.txt" )
)
Wow Salmon!!. thanks very much. it worked like a charm
warm regards Helen Quote from: Helen09122010 on July 07, 2012, 01:37:36 AMthe last letter is a , which i want to remove This confused me - I read it as "the last letter is a, which I want to remove." You meant the "The last character is a comma which I want to remove". Commas are not letters, they are punctuation marks. Letters are a-z and A-Z. However letters, numbers, punctuation marks and symbols are all TYPES of character.
|