LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-01-2007, 02:30 PM   #1
igorblackbelt
LQ Newbie
 
Registered: May 2007
Posts: 13

Rep: Reputation: 0
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!
 
Old 05-01-2007, 02:54 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.
 
Old 05-01-2007, 03:14 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
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.
 
Old 05-02-2007, 12:29 PM   #4
igorblackbelt
LQ Newbie
 
Registered: May 2007
Posts: 13

Original Poster
Rep: Reputation: 0
People,
I resolved the issue with head -c 4999 filename > filename1

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

Thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash remove part of a file based on contents of another file bhepdogg Programming 4 01-31-2007 03:13 PM
s bit VS core file toubo Linux - General 2 10-20-2004 11:26 AM
c++ file processing -- how to remove a record from a file sharonyiisl Programming 4 09-26-2004 03:54 AM
find / \( -perm -0200 -o -perm -04000 \) -ls. How to remove the bit ForumKid Linux - Security 3 01-16-2002 11:36 AM
How to remove a SetXid bit for a particular file ForumKid Linux - General 3 01-03-2002 07:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration