-   Linux - Newbie (
-   -   How to remove last charachter (last bit) from file? (

igorblackbelt 05-01-2007 02:30 PM

How to remove last charachter (last bit) from file?
Hello guys,

I'm totally new to Linux and need to remove the very last character from a file, which seems to be causing the problem to load to our sql databases, I remember to have used a combination of mv with wc -c (-1) previously, but it has been such a long time ago that I don't remember... Unless you guys have anything else in mind. Thanks in advance!

jschiwal 05-01-2007 02:54 PM

If the file an sql dump. I'm wondering if the problem is that it was saved in windows and has a LF added. If that is the case, maybe you could use the "dos2unix" program. Do it on a copy because I've never used it on a very long program.

You could also use dd and copy one less than the size of the file if it really is the end of the file.

You might want to study the situation first, by using dd with an offset near the end of the file and pipe the output through "od" to see how the file ends.

pixellany 05-01-2007 03:14 PM

Last character = last byte (not bit)

Do you need to do this to just one file? If so, just use an editor

Otherwise, write a small script using---eg
cat <filename>|head -c -1 > <newfilename>

The "head -c -1" outputs every byte in the file except the last one

to do this on a bunch of files with different names, the script needs to remember the filename and then append something to it to make the new file.

igorblackbelt 05-02-2007 12:29 PM

I resolved the issue with head -c 4999 filename > filename1

The real bite count for my file was 5000, that worked.


All times are GMT -5. The time now is 04:48 PM.