Please can you let me know how I can delete the last line of a TXT
file. For example my file is called "fileA.txt" and I will like to
run a batch to delete the list line in "fileA.txt". i.e. FileA is
currently:
1,NAME
I would just like to display
1,NAME
removing the carriage return.
Thanks,
Brett
Saying you want to do it in a batch file rather than saying you want to
do it in batch language leaves an opening for a simple solution:
head --lines=-1 infile > outfile
where head is from the GnuWin32 (free and open source) CoreUtils package:
http://gnuwin32.sourceforge.net/packages/coreutils.htm
--
T.E.D. (tda...@mst.edu)
I fixed the issue, the problem was with the copy command I was using.
I am now using copy /b *.TXT NewFile.TXT. Now there is no
carriagereturns.
Thanks,
Brett
I've exactply the same problem : how can i use FIND to filter out these
lines? "FIND" or "FINDSTR" can find these lines, but when i use ">" to
output a file, the output itself contains that char!
:-(((
Are you using something like this?
find "1,NAME" <"filein.txt" >"fileout.txt"
--
Regards,
Mic
yes :-/
>>> I've exactply the same problem : how can i use FIND to filter out
>>> these lines? "FIND" or "FINDSTR" can find these lines, but when i
>>> use ">" to output a file, the output itself contains that char!
>>>
>>> :-(((
>>
>> Are you using something like this?
>>
>> find "1,NAME" <"filein.txt" >"fileout.txt"
>
>yes :-/
>
Please explain your problem and show us what is in the file before and
afterwards.
--
Regards,
Mic
I suspect that OP's problem was that copy was appending a ^Z, not a
"carriage return" as claimed. This would be cured by the /b switch.
So what is "that char" that you don't want in the output? Do you actually
want a Unix-style 0AH new-line rather than 0D0AH? If so, I'd use a SED port,
and look for Eric Pement's SED one-liners.
>
sorry if my english isn't too good...
in the DOS times i were able to tell you what this char could be... but now
i've lost this skill.
I have a file that comes out by an export function of a program, and in a
phase of my workflow another program need to import it ... but it in some
parsing moment it doesn't pass the check: if I open the file with a simple
notepad, erase the "square" char in the last line resulting in the last
data-line is the real last line, all goes well.
but if i try to use FIND or FINDSTR with input: file_with_wrong_char and
>output_file , i have another file with a wrong line.
see the problem in response of "bilious" post;
but sorry: i am not able to tell you exactly the content of the file... some
of the informations are strictly reserved (in each correct line) ... last
line has a wrong char.
maybe i can use the gnu program as suggested by Tedd Davis... because infact
it's
the LAST line ... i hope well ... don't know if the program can run without
excessive requirements (dll, libraries...) ... because at the end of the
work i have to leave the result to a user workstation without administrative
rights...
thanks for any help you can give me , folks!
>see the problem in response of "bilious" post;
>but sorry: i am not able to tell you exactly the content of the file... some
>of the informations are strictly reserved (in each correct line) ... last
>line has a wrong char.
>maybe i can use the gnu program as suggested by Tedd Davis... because infact
>it's
>the LAST line ... i hope well ... don't know if the program can run without
>excessive requirements (dll, libraries...) ... because at the end of the
>work i have to leave the result to a user workstation without administrative
>rights...
>
>thanks for any help you can give me , folks!
If the file has something you can filter on then this works here. I
filtered on the character "a"
find "a" <file4.txt >file6.txt
--
Regards,
Mic
if i use the filter as is, it works, if i use it outputting in another file,
this creates the same character i try to filter with it
I suspect that if FIND or FINDSTR is producing an output that still contains
the unwanted character(s) then the actual format of the input file is
string_containing_wanted_data[CR]unwanted_character(s)
Without knowing the exact format or the actual (hex-value of) unwanted
characters, this could be difficult.
I'd try
for /f "delims=" %%i in ( ' find "wanted" ^<filename ' ) do set var=%%i
>outfilename echo=%var:~0,-2%
(two lines)
Where "-2" removes the last 2 characters - may need to be changed to suit
the circumstance, depending on the length of the unwanted sequence.